首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当字段包含感叹号时,从Elasticsearch中丢失突出显示的文本

当字段包含感叹号时,从Elasticsearch中丢失突出显示的文本
EN

Stack Overflow用户
提问于 2020-02-14 09:49:05
回答 2查看 641关注 0票数 1

当搜索文本并请求结果查询突出显示时,如果匹配的文档字段包含感叹号,则返回的高亮显示文本不包含包含感叹号的部分文本。

Elasticsearch版本7.1.1

文档:{ "name" : "Yahoo! Inc [Please refer to Altaba Inc and Verizon Communications Inc]"}搜索并突出显示"inc“通配符

预期的突出显示的文本应该是:

代码语言:javascript
复制
"Yahoo! <em>Inc</em> [Please refer to Altaba <em>Inc</em> and Verizon Communications <em>Inc</em>]"

实战:“雅虎!”在回应中不见了。Got:

代码语言:javascript
复制
"<em>Inc</em> [Please refer to Altaba <em>Inc</em> and Verizon Communications <em>Inc</em>]"

我觉得这跟这事有关!马克。如果我把它去掉,那么一切都没问题。

复制步骤:

将文档添加到新索引中

代码语言:javascript
复制
POST test/_doc/ { "name" : "Yahoo! Inc [Please refer to Altaba Inc and Verizon Communications Inc]" }

没有其他设置/映射

运行查询

代码语言:javascript
复制
GET test/_search { "query": { "bool": { "should": [ { "wildcard": { "name": { "wildcard": "inc*" } } } ] } }, "highlight": { "fields": { "name" : {} } } }

结果如下:

代码语言:javascript
复制
"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>]" ] } } ]

期待突出:

代码语言:javascript
复制
"Yahoo! <em>Inc</em> [Please refer to Altaba <em>Inc</em> and Verizon Communications <em>Inc</em>]"
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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,我将强制突出显示返回整个文档字段。

代码语言:javascript
复制
"highlight": {
  "fields": {
     "name" : {"number_of_fragments" : 0}
  }
}

与:https://github.com/elastic/elasticsearch/issues/52333相同

票数 5
EN

Stack Overflow用户

发布于 2022-05-05 16:31:23

正如andreyro所说,统一(默认) Elasticsearch荧光笔的行为是预期的。我有同样的问题,减少碎片的数量只是使问题变得更糟。幸运的是,您可以更改所使用的荧光笔。我添加了以下内容,问题就解决了。

代码语言:javascript
复制
"highlight": {
    "fields": {
        "*": {
            "type": "plain"
        }
    }
}

根据需要替换您正在搜索的任何字段的通配符"*“。请参阅相同的文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html#set-highlighter-type

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60223820

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档