gpt4 book ai didi

Elasticsearch 使用 multi_match 突出显示

转载 作者:行者123 更新时间:2023-11-29 02:55:32 25 4
gpt4 key购买 nike

我在简单的匹配查询中使用了 ES 的高亮显示:

GET /_search
{
"query": {
"match": {
"Text": "key words here"
}
},
"highlight": {
"pre_tags" : ["<span class='highlighter'>"],
"post_tags" : ["</span>"],
"fields": {
"Text": {
"fragment_size": 400,
"number_of_fragments": 1,
"no_match_size" : 20
}
}
}
}

这很好用,并在结果中返回带有指定标签的高亮文本。

我想像这样在 multi_match 查询上使用突出显示:

GET /_search
{
"query": {
"multi_match": {
"query": "GB RAM",
"operator": "AND",
"fields": "_all"
}
},
"highlight": {
"pre_tags": [
"<span class='highlighter'>"
],
"post_tags": [
"</span>"
],
"fields": {
"Text": {
"fragment_size": 400,
"number_of_fragments": 1,
"no_match_size": 20
}
}
}
}

这不太有效,返回的高亮文本长度为 20 个字符(no_match_size),如下所示:

 "highlight": {
"Text": [" DVD-RAM"]
}

我在这里做错了什么?

最佳答案

您必须先修改映射以在映射中启用 store:true。自 highlight need exact string它作为 _all 字段工作的值不包含在源代码中。

更改映射以将 store:true 设置为 _all

放置 highlight_index_2

{
"mappings": {
"type_1" : {
"_all": {
"enabled": true,
"store": true
}
}
}
}

接下来您需要稍微调整一下查询。由于您的查询指定 lucene 荧光笔仅针对文本字段突出显示,因此您只会获得文本字段的高亮显示。您可以像下面这样修改您的查询

{
"query": {
"query_string": {
"fields": [
"_all"
],
"query": "this is the"
}
},
"highlight": {
"pre_tags": [
"<span class='highlighter'>"
],
"post_tags": [
"</span>"
],
"fields": {
"_all": {
"fragment_size": 400,
"number_of_fragments": 2,
"no_match_size": 20
}
}
}
}

确保调整片段数量以突出显示多个字段。

关于Elasticsearch 使用 multi_match 突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43995578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com