Elasticsearch 8.7.x中keyword_repeat导致bool should查询结果异常
Elasticsearch 8.7.0/8.7.1版本keyword_repeat过滤器导致bool查询异常问题
在Elasticsearch 8.7.0及8.7.1版本中,当索引配置使用keyword_repeat过滤器时,执行包含should子句的bool查询会出现异常:仅匹配should列表中的第一个字段,调换字段顺序后才能正常找到目标文档。移除keyword_repeat过滤器后,查询恢复正常;而8.6.2、8.8.0/8.8.1版本无此问题。
重现步骤
1. 创建索引
curl -X PUT "elasticsearch:9200/my-test-index?pretty" -H 'Content-Type: application/json' -d' { "settings": { "analysis": { "analyzer": { "default": { "tokenizer": "default_tokenizer", "filter": [ "lowercase", "keyword_repeat", "default_stemmer" ] } }, "tokenizer": { "default_tokenizer": { "type": "standard" } }, "filter": { "default_stemmer": { "type": "stemmer", "language": "english" }, "unique_stem": { "type": "unique", "only_on_same_position": true } } } }, "mappings": { "properties": { "field1": { "type": "text" }, "field2": { "type": "text" } } } } '
2. 插入文档
curl -X POST "elasticsearch:9200/my-test-index/_doc/1?pretty" -H 'Content-Type: application/json' -d' { "field1": "running man", "field2": "other text" } '
3. 异常查询(无结果返回)
curl -X GET "elasticsearch:9200/my-test-index/_search?pretty" -H 'Content-Type: application/json' -d' { "query": { "bool": { "should": [ { "match": { "field2": "running" }}, { "match": { "field1": "running" }} ] } } } '
4. 正常查询(调换字段顺序后返回目标文档)
curl -X GET "elasticsearch:9200/my-test-index/_search?pretty" -H 'Content-Type: application/json' -d' { "query": { "bool": { "should": [ { "match": { "field1": "running" }}, { "match": { "field2": "running" }} ] } } } '
现象分析
通过_termvectors查看索引词项,field1包含"running"和"run"等有效词项,但异常查询无法匹配到该字段,仅当调换should子句中的字段顺序时,才能命中目标文档。
内容的提问来源于stack exchange,提问作者Ilya
相关产品推荐
相关产品推荐

