Highlighting matched results on _all fields

前端 未结 4 1136
一生所求
一生所求 2021-01-05 00:51

I want the matched results to be highlighted. This works for me if I mention the field name and it returns the highlighted text, however if I give the field as \"_all\", it

相关标签:
4条回答
  • 2021-01-05 01:28

    This library has functions for query highlighting including highlighting across all fields. The README explains how to create an elasticsearch index with _all field stored etc: https://github.com/niranjan-uma-shankar/Elasticsearch-PHP-class

    0 讨论(0)
  • 2021-01-05 01:37

    You need to map the _all field as stored. The mapping below should do the trick. Note though that this will add to the index size.

    {
      "my_type": {
          "_all": {
            "enabled": true,
            "store": "yes"
          }
      }}
    
    0 讨论(0)
  • 2021-01-05 01:37

    If you are using ES 2.x then you need to set require_field_match option to false due to changes made, From the doc

    The default value for the require_field_match option has changed from false to true, meaning that the highlighters will, by default, only take the fields that were queried into account.

    This means that, when querying the _all field, trying to highlight on any field other than _all will produce no highlighted snippets.

    "highlight": {
        "fields": {
          "*": {}
        },
        "require_field_match": false
     }
    
    0 讨论(0)
  • 2021-01-05 01:46

    To avoid the need to add _all as a stored field in your index

    An alternative quick fix: use * instead of _all:

    curl -XGET "http://localhost:9200/my_index/my_type/_search?q=stackoverflow&size=999" -d '{
      "highlight":{
        "fields":{
          "*":{}
        }
      }
    }'
    
    0 讨论(0)
提交回复
热议问题