Remove duplicates token filter
출처: 문서
본문
Remove duplicates 토큰 필터
remove_duplicates 토큰 필터는 분석 과정에서 같은 위치에 생성된 중복 토큰을 제거하는 데 사용해요.
예제
다음 예제 요청은 keyword_repeat 토큰 필터가 포함된 인덱스를 생성해요. 이 필터는 각 토큰의 keyword 버전을 토큰 자체와 같은 위치에 추가한 뒤, kstem을 사용해 토큰의 어간 추출(stemmed) 버전을 만들어요:
PUT /example-index
{
"settings": {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"keyword_repeat",
"kstem"
]
}
}
}
}
}
{% include copy-curl.html %}
다음 요청을 사용해 Slower turtle 문자열을 분석해 보세요:
GET /example-index/_analyze
{
"analyzer": "custom_analyzer",
"text": "Slower turtle"
}
{% include copy-curl.html %}
응답에는 turtle 토큰이 같은 위치에 두 번 포함되어 있어요:
{
"tokens": [
{
"token": "slower",
"start_offset": 0,
"end_offset": 6,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "slow",
"start_offset": 0,
"end_offset": 6,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "turtle",
"start_offset": 7,
"end_offset": 13,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "turtle",
"start_offset": 7,
"end_offset": 13,
"type": "<ALPHANUM>",
"position": 1
}
]
}
인덱스 설정에 remove_duplicates 토큰 필터를 추가하면 중복 토큰을 제거할 수 있어요:
PUT /index-remove-duplicate
{
"settings": {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"keyword_repeat",
"kstem",
"remove_duplicates"
]
}
}
}
}
}
{% include copy-curl.html %}
생성된 토큰
다음 요청을 사용해 애널라이저로 생성된 토큰을 확인해 보세요:
GET /index-remove-duplicate/_analyze
{
"analyzer": "custom_analyzer",
"text": "Slower turtle"
}
{% include copy-curl.html %}
응답에는 생성된 토큰이 포함되어 있어요:
{
"tokens": [
{
"token": "slower",
"start_offset": 0,
"end_offset": 6,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "slow",
"start_offset": 0,
"end_offset": 6,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "turtle",
"start_offset": 7,
"end_offset": 13,
"type": "<ALPHANUM>",
"position": 1
}
]
}