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

Apostrophe token filter

원문 보기 위키 갱신

출처: 문서

본문

Apostrophe 토큰 필터

apostrophe 토큰 필터의 주요 기능은 소유격 아포스트로피와 그 뒤에 따라오는 내용을 제거하는 거예요. 터키어처럼 아포스트로피를 많이 사용하는 언어, 즉 아포스트로피가 어근과 접미사(소유 접미사, 격 표지, 기타 문법적 어미 등)를 구분해 주는 언어의 텍스트를 분석할 때 아주 유용할 수 있어요.

예제

다음 예제 요청은 settings에 커스텀 분석기를 설정하고 mappings에서 사용하는, custom_text_index라는 새 인덱스를 생성해요:

PUT /custom_text_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "apostrophe"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "custom_analyzer"
      }
    }
  }
}

{% include copy-curl.html %}

생성된 토큰

생성한 분석기가 만들어내는 토큰을 확인하려면 다음 요청을 사용해 보세요:

POST /custom_text_index/_analyze
{
  "analyzer": "custom_analyzer",
  "text": "John's car is faster than Peter's bike"
}

{% include copy-curl.html %}

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

{
  "tokens": [
    {
      "token": "john",
      "start_offset": 0,
      "end_offset": 6,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "car",
      "start_offset": 7,
      "end_offset": 10,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "is",
      "start_offset": 11,
      "end_offset": 13,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "faster",
      "start_offset": 14,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 3
    },
    {
      "token": "than",
      "start_offset": 21,
      "end_offset": 25,
      "type": "<ALPHANUM>",
      "position": 4
    },
    {
      "token": "peter",
      "start_offset": 26,
      "end_offset": 33,
      "type": "<ALPHANUM>",
      "position": 5
    },
    {
      "token": "bike",
      "start_offset": 34,
      "end_offset": 38,
      "type": "<ALPHANUM>",
      "position": 6
    }
  ]
}

내장 apostrophe 토큰 필터는 단어 시작 부분에 아포스트로피를 사용하는 프랑스어 같은 언어에는 적합하지 않아요. 예를 들어 "C'est l'amour de l'école"은 "C", "l", "de", "l"이라는 네 개의 토큰이 돼요. {: .note}

더 알아보기 (Learn more)