在ElasticSearch中突出显示匹配短语而不是单词短语

balp4ylt  于 5个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(51)

我们正在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
我们搜索了一下,发现了这个问题,但它与Sorl有关。
它说有两个可能的参数(来自Lucene)用于此目的:usePhraseHighlightermergeContiguous
那么,我们如何才能得到一个完整的短语高亮显示结果,而不是单独高亮显示每个单词的短语查询?
谢谢

相关问题