Elasticsearch“AND”运算符不像预期的那样与突出显示查询一起工作

lnxxn5zx  于 12个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(111)

我在Elasticsearch中遇到了一个问题,我使用了一个带有“AND”运算符的突出显示查询,但它匹配的文档并不包含查询中所有指定的术语。这是我的Elasticsearch查询和文档

curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d '{
    "query": {
        "terms": {
            "bidAwardId": [
                "05141cde-fd82-4c50-8751-72484bbdafe4"
            ],
            "boost": 1.0
        }
    },
    "highlight": {
        "fields": {
            "aocDescription.strValue": {
                "fragment_size": 150,
                "highlight_query": {
  "bool" : {
    "should" : [
      {
        "match" : {
          "description.strValue" : {
            "query" : "solar stud road",
            "operator": "AND"
          }
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}
            }
        }
    }
}'

输出中突出显示的内容如下:

"highlight" : {
          "description.strValue" : [
            "Remaining Work of Widening and Strengthening of Simdega-Rengari-Kersai-Bolba upto Orissa Border <em>Road</em>"
          ]
        }

突出显示字段包含不包含日光或柱的片段。如果匹配查询中有“AND”运算符,则应该是这种情况。

t8e9dugd

t8e9dugd1#

highlight_query参数中指定的查询仅用于提取关键字以突出显示。没有尝试实际检查它是否与突出显示的文档匹配,或者强制执行布尔逻辑或您的查询。实际上,即使对于主查询也是如此。
请检查documentation on the highlighting。在注解部分的顶部,
在提取要突出显示的词时,突出显示器不反映查询的布尔逻辑。因此,对于一些复杂的布尔查询(例如嵌套的布尔查询,使用minimum_should_match的查询等),可能会突出显示不对应于查询匹配的文档部分。
您可以尝试切换到plain荧光笔。这个荧光笔实际上在内存中索引文档,以便更好地确定哪些字段匹配以及在哪里匹配。因此,虽然它要慢得多,需要更多的内存,但它通常会产生更接近您预期的结果。

相关问题