【发布时间】:2020-09-25 13:39:16
【问题描述】:
我在 test_plain_highlighter 下创建了索引。我希望突出显示的片段应该按照在字段中出现的顺序出现,使用Plain荧光笔。
我尝试了以下选项,
- 在高亮查询中设置"order":"none"(如下查询所示)。
- 无顺序在高亮查询中定义。
- 在高亮查询中设置"order":"score"。
但是,它总是给出突出显示的片段基于分数排序。我希望它按出现在字段中的顺序。请帮帮我。
订购
设置为
score时,按分数对突出显示的片段进行排序。默认情况下,片段将按照它们在字段中出现的顺序输出(顺序:none)。将此选项设置为score将首先输出最相关的片段。每个荧光笔都应用自己的逻辑来计算相关性分数。有关不同荧光笔如何找到最佳片段的更多详细信息,请参阅文档How highlighters work internally。
PUT test_plain_highlighter
{}
POST /test_plain_highlighter/_doc/1
{
"description" : "Lorem Ipsum string Generator that helps to create dummy text for all layout needs. In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to Apple's Pages and Keynote software employs such jumbled text as sample screenplay layout. search facial Lorem ipsum is also featured on Joomla. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it search string over 2000 years old."
}
请求
POST /test_plain_highlighter/_search
{
"highlight": {
"order": "none",
"type": "plain",
"fields": {
"*": {}
},
"fragment_size": 50
},
"query": {
"match": {
"description": "search string"
}
},
"_source": ""
}
回复
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.79659015,
"hits" : [
{
"_index" : "test_plain_highlighter",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.79659015,
"_source" : { },
"highlight" : {
"description" : [
", making it <em>search</em> <em>string</em> over 2000 years old.",
"Lorem Ipsum <em>string</em> Generator that helps to create",
" layout. <em>search</em> facial Lorem ipsum is also"
]
}
}
]
}
}
收到突出显示的片段:
[
", making it `<em>search</em>` `<em>string</em>` over 2000 years old.",
"Lorem Ipsum `<em>string</em>` Generator that helps to create",
" layout. `<em>search</em>` facial Lorem ipsum is also"
]
预期的高亮片段:
[
"Lorem Ipsum `<em>string</em>` Generator that helps to create",
" layout. `<em>search</em>` facial Lorem ipsum is also",
", making it `<em>search</em>` `<em>string</em>` over 2000 years old."
]
【问题讨论】:
标签: elasticsearch highlight lucene-highlighter