elasticsearch - 当字段包含感叹号时,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>]"
实际: “雅虎!” 响应中缺少。拿到:
"<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>]"
解决方案
这是预期的行为,因为默认情况下,Elasticsearch 突出显示返回搜索文本(片段)的一部分,请参见: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}
}
}
推荐阅读
- r - 是否有可能在按时间索引的 r 中滞后数据帧的值?
- python - Pytorch 模型中所有梯度的列表
- android - Android Studio 分析无穷大
- java - 选择排序与插入排序:8 和 14 Java 版本的不同处理时间
- jquery - 如何添加到按钮“jQuery 确认”以确认工作
- google-search-console - 错误“只应标记一个综合评分”
- c - feof 导致分段错误(核心转储)错误?
- python - 使用列表中提到的特定列值从 CSV 获取整行
- android - 在 2 个 Android 应用程序之间共享数据
- r - 在 x 轴上绘制 R - 标签