弹性搜索突出显示API突出显示所有已删除的单词

时间:2017-02-09 13:27:14

标签: elasticsearch

我在弹性搜索中索引了如下文档。

文件:

{{"ID:1, "Cont": "yes there is a match"},
  {"ID":2, "Cont": "check this for it"} ....}

当我使用突出显示搜索文档时。

http://localhost:9200/sample/html/_search
{
    "query": 
        {"bool": {  
            "should": [{"match": {"Content": "check mate"}}]}},
    "highlight" : {
        "fields" : {
            "Content" : {}
        }
    }
}

输出如下。

"highlight": {
      "Content": ["<em>check</em> blaa", "blaa blaa<em>check</em>"]
}

从突出显示输出看起来,检查在两个地方匹配,但是当我打开文档并看到有15次检查时,也有匹配文档中配合

  1. 有没有办法在高亮列中获取所有匹配的单词,即获得此示例的检查和配对。

    2.有没有办法获得匹配发生次数,即)check = 15,mate = 1

1 个答案:

答案 0 :(得分:1)

关于您的第一个问题:

您可以使用number_of_fragments选项获取更多精彩片段。默认情况下,它设置为2(这就是为什么你只能看到2个亮点)。例如,如果要查看更多内容,可以将其设置为100.

您还可以将number_of_fragments设置为0,这不会将您的内容分段以显示突出显示,但会突出显示您的整个内容(然后您会看到所有突出显示的内容) )。

文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#_highlighted_fragments

第二个问题:

据我所知,我认为这不可能......你必须从我非常害怕的重点结果中算出来......

相关问题