본문 바로가기
WIKI 기술 지식 베이스

Simple analyzer

원문 보기 위키 갱신

출처: 문서

본문

Simple 애널라이저

simple 애널라이저는 텍스트를 알파벳이 아닌 문자를 기준으로 텀으로 분리하고, 텀을 소문자로 바꾸는 아주 기본적인 애널라이저예요. standard 애널라이저와 달리, simple 애널라이저는 알파벳 문자를 제외한 모든 것을 구분자로 취급해요. 즉, 숫자, 문장 부호, 특수 문자는 토큰의 일부로 인식하지 않아요.

예시

다음 명령어를 사용하면 simple 애널라이저를 적용한 my_simple_index라는 이름의 인덱스를 생성할 수 있어요:

PUT /my_simple_index
{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "text",
        "analyzer": "simple"
      }
    }
  }
}

{% include copy-curl.html %}

커스텀 애널라이저 설정하기

다음 명령어를 사용하면 html_strip 캐릭터 필터가 추가된 simple 애널라이저와 동일하게 동작하는 커스텀 애널라이저로 인덱스를 설정할 수 있어요:

PUT /my_custom_simple_index
{
  "settings": {
    "analysis": {
      "char_filter": {
        "html_strip": {
          "type": "html_strip"
        }
      },
      "tokenizer": {
        "my_lowercase_tokenizer": {
          "type": "lowercase"
        }
      },
      "analyzer": {
        "my_custom_simple_analyzer": {
          "type": "custom",
          "char_filter": ["html_strip"],
          "tokenizer": "my_lowercase_tokenizer",
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "my_field": {
        "type": "text",
        "analyzer": "my_custom_simple_analyzer"
      }
    }
  }
}

{% include copy-curl.html %}

생성된 토큰

다음 요청을 사용해서 애널라이저가 생성한 토큰을 확인해 보세요:

POST /my_custom_simple_index/_analyze
{
  "analyzer": "my_custom_simple_analyzer",
  "text": "<p>The slow turtle swims over to dogs &copy; 2024!</p>"
}

{% include copy-curl.html %}

응답에는 생성된 토큰이 담겨 있어요:

{
  "tokens": [
    {"token": "the","start_offset": 3,"end_offset": 6,"type": "word","position": 0},
    {"token": "slow","start_offset": 7,"end_offset": 11,"type": "word","position": 1},
    {"token": "turtle","start_offset": 12,"end_offset": 18,"type": "word","position": 2},
    {"token": "swims","start_offset": 19,"end_offset": 24,"type": "word","position": 3},
    {"token": "over","start_offset": 25,"end_offset": 29,"type": "word","position": 4},
    {"token": "to","start_offset": 30,"end_offset": 32,"type": "word","position": 5},
    {"token": "dogs","start_offset": 33,"end_offset": 37,"type": "word","position": 6}
  ]
}

더 알아보기 (Learn more)