Flatten graph token filter
출처: 문서
본문
Flatten graph 토큰 필터
flatten_graph 토큰 필터는 그래프 구조에서 여러 토큰이 같은 위치에 생성될 때 발생하는 복잡한 토큰 관계를 처리하는 데 사용해요. synonym_graph, word_delimiter_graph 같은 일부 토큰 필터는 멀티 포지션 토큰---여러 위치에 걸치거나 겹치는 토큰---을 생성해요. 이런 토큰 그래프는 검색 쿼리에는 유용하지만 인덱싱 중에는 직접 지원되지 않아요. flatten_graph 토큰 필터는 멀티 포지션 토큰을 선형 토큰 시퀀스로 변환해 줘요. 그래프를 평탄화하면 인덱싱 프로세스와의 호환성이 보장돼요.
토큰 그래프 평탄화는 손실이 일어나는 과정이에요. 가능하다면 flatten_graph 필터 사용은 피하세요. 대신 그래프 토큰 필터를 검색 분석기에만 적용하면 flatten_graph 필터가 필요 없어져요.
{: .important}
예제
다음 예제 요청은 test_index라는 새 인덱스를 만들고 flatten_graph 필터가 적용된 분석기를 구성해요:
PUT /test_index
{
"settings": {
"analysis": {
"analyzer": {
"my_index_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"my_custom_filter",
"flatten_graph"
]
}
},
"filter": {
"my_custom_filter": {
"type": "word_delimiter_graph",
"catenate_all": true
}
}
}
}
}
{% include copy-curl.html %}
생성된 토큰
다음 요청을 사용해서 분석기가 생성한 토큰을 확인해 보세요:
POST /test_index/_analyze
{
"analyzer": "my_index_analyzer",
"text": "OpenSearch helped many employers"
}
{% include copy-curl.html %}
응답에는 생성된 토큰이 담겨 있어요:
{
"tokens": [
{
"token": "OpenSearch",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0,
"positionLength": 2
},
{
"token": "Open",
"start_offset": 0,
"end_offset": 4,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "Search",
"start_offset": 4,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "helped",
"start_offset": 11,
"end_offset": 17,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "many",
"start_offset": 18,
"end_offset": 22,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "employers",
"start_offset": 23,
"end_offset": 32,
"type": "<ALPHANUM>",
"position": 4
}
]
}