没有找到句子中断时,Elasticsearch高亮代码段不以匹配为中心

时间:2019-05-23 09:36:21

标签: elasticsearch highlight

Elasticsearch中有一些文档缺少标点符号。

我发现,当文档没有句子中断时,Elasticsearch突出显示不会将代码段居中于匹配的单词上,而是将显示导致匹配的代码段。

有什么办法可以改变这一点,从而使摘要位于单词的中心吗?

复制:

PORT=9400

curl -X PUT "localhost:$PORT/test" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "transcript" : { "type" : "text" }
            }
        }
    }
}
'

curl -X PUT "localhost:$PORT/test/_doc/1" -H 'Content-Type: application/json' -d'
{
  "transcript":"Lo! the Spear-Danes glory through splendid achievements The folk-kings former fame we have heard of, How princes displayed then their prowess-in-battle Oft Scyld the Scefing from scathers in numbers From many a people their mead-benches tore Since first he found him friendless and wretched"
}'

curl "localhost:$PORT/test/_search" -H 'Content-Type: application/json' -d'
{
    "query": {
                "query_string": {
                    "query": "displayed",
                    "fields": ["transcript"]
                }
    },
    "highlight": {       
        "fields": {"transcript": {}}
    }
}
'

返回:

"highlight":{"transcript":["Spear-Danes glory through splendid achievements The folk-kings former fame we have heard of, How princes <em>displayed</em>"]}}

...,且匹配项位于代码段的末尾。如何在摘要中间找到匹配项?

0 个答案:

没有答案