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

Keep words token filter

원문 보기 위키 갱신

출처: 문서

본문

Keep words 토큰 필터

keep_words 토큰 필터는 분석 과정에서 특정 단어만 남기도록 설계되었어요. 대량의 텍스트 중에서 특정 키워드나 용어에만 관심이 있을 때 이 필터가 유용해요.

파라미터

keep_words 토큰 필터는 다음 파라미터로 설정할 수 있어요.

파라미터 필수/선택 데이터 타입 설명
keep_words keep_words_path가 설정되지 않은 경우 필수 List of strings 유지할 단어 목록이에요.
keep_words_path keep_words가 설정되지 않은 경우 필수 String 유지할 단어 목록이 담긴 파일의 경로예요.
keep_words_case 선택 Boolean 비교 시 모든 단어를 소문자로 변환할지 여부예요. 기본값은 false예요.

예제

다음 예제 요청은 my_index라는 새 인덱스를 생성하고 keep_words 필터가 설정된 분석기를 구성해요:

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_keep_word": {
          "tokenizer": "standard",
          "filter": [ "keep_words_filter" ]
        }
      },
      "filter": {
        "keep_words_filter": {
          "type": "keep",
          "keep_words": ["example", "world", "opensearch"],
          "keep_words_case": true
        }
      }
    }
  }
}

{% include copy-curl.html %}

생성된 토큰

다음 요청을 사용해서 분석기로 생성된 토큰을 확인할 수 있어요:

GET /my_index/_analyze
{
  "analyzer": "custom_keep_word",
  "text": "Hello, world! This is an OpenSearch example."
}

{% include copy-curl.html %}

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

{
  "tokens": [
    {
      "token": "world",
      "start_offset": 7,
      "end_offset": 12,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "OpenSearch",
      "start_offset": 25,
      "end_offset": 35,
      "type": "<ALPHANUM>",
      "position": 5
    },
    {
      "token": "example",
      "start_offset": 36,
      "end_offset": 43,
      "type": "<ALPHANUM>",
      "position": 6
    }
  ]
}

더 알아보기 (Learn more)