我们正在使用ElasticSearch中的过滤器,我们需要逐字逐句完整地突出显示:
例如,我们有下一个搜索:
curl -X GET "localhost:9200/my-index/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"percolate" : {
"field": "query",
"document" : {
"title" : "A new bonsai tree in the office and jungle. The enojen tree in a kerojen."
}
}
},
"highlight": {
"fields": {
"title": {}
}
}
}
'
然后我们得到下一个输出:
{
"took":12,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":45,
"max_score":2.1576157,
"hits":[
{
"_index":"my-index",
"_type":"_doc",
"_id":"2",
"_score":2.1576157,
"_source":{
"query":{
"match":{
"title":"the enojen tree in a kerojen"
}
}
},
"fields":{
"_percolator_document_slot":[
0
]
},
"highlight":{
"title":[
"<em>A</em> new bonsai <em>tree</em> <em>in</em> <em>the</em> office and jungle. <em>The</em> <em>enojen</em> <em>tree</em> <em>in</em> <em>a</em> <em>kerojen</em>."
]
}
},
{
"_index":"my-index",
"_type":"_doc",
"_id":"1",
"_score":2.1576157,
"_source":{
"query":{
"match":{
"title":"the bonsai tree in a jungle"
}
}
},
"fields":{
"_percolator_document_slot":[
0
]
},
"highlight":{
"title":[
"<em>A</em> new <em>bonsai</em> <em>tree</em> <em>in</em> <em>the</em> office and <em>jungle</em>. <em>The</em> enojen <em>tree</em> <em>in</em> <em>a</em> kerojen."
]
}
}
]
}
}
正如您所看到的,我们正在逐字逐句地分割所有突出显示的匹配,但我们希望得到如下内容:<em>The enojen tree in a kerojen</em>
;它有一个相关的issue。
我们正在搜索它,我们发现了这个question,但它与Sorl
有关。
它说为此目的有两个可能的参数(来自Lucene):usePhraseHighlighter
和mergeContiguous
。
那么,我们如何才能获得一个完整的短语突出显示结果,而是单独突出显示每个单词的短语查询?
谢谢。