お世話になっております。
当方、elasticsearch9.4で動作確認を行っております。
intervalsクエリで、同一の文字列(複数トークン)を指定したときの距離のカウント方法に違和感があるのですが、どのようなカウントになっているのかご教示いただければ幸いです。
■インデックス設定、データ投入
PUT test_intervals
{
"settings": {
"analysis": {
"tokenizer": {
"my_ngram_tok": {"type": "ngram","min_gram": 1,"max_gram": 1}
},
"analyzer": {
"my_unigram": {"type": "custom","tokenizer": "my_ngram_tok"}
}
}
},
"mappings": {
"properties": {
"text": {"type": "text","analyzer": "my_unigram"}
}
}
}
POST test_intervals/_doc/1
{
"text": "あいうあいうえおかきくけこ"
}
■検索クエリ
ケース1(OK)
GET test_intervals/_search
{
"query": {
"intervals": {
"text": {
"all_of": {
"ordered": true,
"max_gaps": 2,
"intervals": [
{"match": {"query": "あ","max_gaps": 0,"ordered": true}},
{"match": {"query": "あ","max_gaps": 0,"ordered": true}}
]
}
}
}
}
}
→max_gaps>=2でヒット。納得の動作。
ケース2(OK)
GET test_intervals/_search
{
"query": {
"intervals": {
"text": {
"all_of": {
"ordered": true,
"max_gaps": 1,
"intervals": [
{"match": {"query": "あい","max_gaps": 0,"ordered": true}},
{"match": {"query": "あ","max_gaps": 0,"ordered": true}}
]
}
}
}
}
}
→max_gaps>=1でヒット。納得の動作。
ケース3(???)
GET test_intervals/_search
{
"query": {
"intervals": {
"text": {
"all_of": {
"ordered": true,
"max_gaps": 1,
"intervals": [
{"match": {"query": "あい","max_gaps": 0,"ordered": true}},
{"match": {"query": "あい","max_gaps": 0,"ordered": true}}
]
}
}
}
}
}
→max_gaps=1でヒットしない。5以上ならヒットする。なぜ?
ケース4(OK)
GET test_intervals/_search
{
"query": {
"intervals": {
"text": {
"all_of": {
"ordered": true,
"max_gaps": 2,
"intervals": [
{"match": {"query": "あい","max_gaps": 0,"ordered": true}},
{"match": {"query": "いう","max_gaps": 0,"ordered": true}}
]
}
}
}
}
}
→max_gapsが2以上でヒット。納得。
ご教示いただければ幸いです。