当搜索文本并请求结果查询突出显示时,如果匹配的文档字段包含感叹号,则返回的高亮显示文本不包含包含感叹号的部分文本。
Elasticsearch版本7.1.1
文档:{ "name" : "Yahoo! Inc [Please refer to Altaba Inc and Verizon Communications Inc]"}搜索并突出显示"inc“通配符
预期的:突出显示的文本应该是:
"Yahoo! <em>Inc</em> [Please refer to Altaba <em>Inc</em> and Verizon Communications <em>Inc</em>]"实战:“雅虎!”在回应中不见了。Got:
"<em>Inc</em> [Please refer to Altaba <em>Inc</em> and Verizon Communications <em>Inc</em>]"我觉得这跟这事有关!马克。如果我把它去掉,那么一切都没问题。
复制步骤:
将文档添加到新索引中
POST test/_doc/ { "name" : "Yahoo! Inc [Please refer to Altaba Inc and Verizon Communications Inc]" }没有其他设置/映射
运行查询
GET test/_search { "query": { "bool": { "should": [ { "wildcard": { "name": { "wildcard": "inc*" } } } ] } }, "highlight": { "fields": { "name" : {} } } }结果如下:
"hits" : [ { "_index" : "test", "_type" : "_doc", "_id" : "511tP3ABoqekxkoUshVf", "_score" : 1.0, "_source" : { "name" : "Yahoo! Inc [Please refer to Altaba Inc and Verizon Communications Inc]" }, "highlight" : { "name" : [ "<em>Inc</em> [Please refer to Altaba <em>Inc</em> and Verizon Communications <em>Inc</em>]" ] } } ]期待突出:
"Yahoo! <em>Inc</em> [Please refer to Altaba <em>Inc</em> and Verizon Communications <em>Inc</em>]"发布于 2020-02-14 09:57:03
这是预期的行为,因为默认情况下,弹性搜索高亮显示返回搜索文本(片段)的一部分(参见:https://www.elastic.co/guide/en/elasticsearch/reference/7.1/search-request-highlighting.html#unified-highlighter )。
好了!还有。被认为是前一句的结尾,而突出显示不返回该片段。
在我的示例中,搜索到的文本表示一个文本长度较小的名称,通过添加"number_of_fragments" : 0,我将强制突出显示返回整个文档字段。
"highlight": {
"fields": {
"name" : {"number_of_fragments" : 0}
}
}发布于 2022-05-05 16:31:23
正如andreyro所说,统一(默认) Elasticsearch荧光笔的行为是预期的。我有同样的问题,减少碎片的数量只是使问题变得更糟。幸运的是,您可以更改所使用的荧光笔。我添加了以下内容,问题就解决了。
"highlight": {
"fields": {
"*": {
"type": "plain"
}
}
}根据需要替换您正在搜索的任何字段的通配符"*“。请参阅相同的文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html#set-highlighter-type
https://stackoverflow.com/questions/60223820
复制相似问题