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

Unique token filter

원문 보기 위키 갱신

출처: 문서

본문

Unique 토큰 필터

unique 토큰 필터는 분석 과정에서 고유한 토큰만 유지되도록 해서, 하나의 필드나 텍스트 블록 안에서 나타나는 중복 토큰을 제거해요.

파라미터

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

파라미터 필수/선택 데이터 타입 설명
only_on_same_position 선택 Boolean true이면 토큰 필터가 remove_duplicates 토큰 필터처럼 동작하며, 같은 위치에 있는 토큰만 제거해요. 기본값은 false예요.

예제

다음 예제 요청은 unique_example이라는 새 인덱스를 생성하고, unique 필터가 설정된 애널라이저를 구성해요:

PUT /unique_example
{
  "settings": {
    "analysis": {
      "filter": {
        "unique_filter": {
          "type": "unique",
          "only_on_same_position": false
        }
      },
      "analyzer": {
        "unique_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "unique_filter"
          ]
        }
      }
    }
  }
}

{% include copy-curl.html %}

생성된 토큰

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

GET /unique_example/_analyze
{
  "analyzer": "unique_analyzer",
  "text": "OpenSearch OpenSearch is powerful powerful and scalable"
}

{% include copy-curl.html %}

응답에는 생성된 토큰이 포함되어 있어요:

{
  "tokens": [
    {
      "token": "opensearch",
      "start_offset": 0,
      "end_offset": 10,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "is",
      "start_offset": 22,
      "end_offset": 24,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "powerful",
      "start_offset": 25,
      "end_offset": 33,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "and",
      "start_offset": 43,
      "end_offset": 46,
      "type": "<ALPHANUM>",
      "position": 3
    },
    {
      "token": "scalable",
      "start_offset": 47,
      "end_offset": 55,
      "type": "<ALPHANUM>",
      "position": 4
    }
  ]
}

더 알아보기 (Learn more)