Elasticsearch Highlight issue on aggregated fields Elasticsearch Highlight issue on aggregated fields elasticsearch elasticsearch

Elasticsearch Highlight issue on aggregated fields


You have to set the highlight inside the top_hits aggregation properties (not inside of aggregation).

Here is a working minimal example:

echo create indexcurl -XPUT 'http://127.0.0.1:9010/files?pretty=1' -d '{  "settings": {  }}'echo create typecurl -XPUT 'http://127.0.0.1:9010/files/_mapping/file?pretty=1' -d'{  "properties":{    "fileName":{      "type":"string",      "term_vector":"with_positions_offsets"    }  }}'echo insert filescurl -XPUT 'http://127.0.0.1:9010/files/file/1?pretty=1' -d'{  "fileName":"quick brown fox"}'echo flushcurl -XPOST 'http://127.0.0.1:9010/files/_flush?pretty=1'echo search brown tophitscurl -XGET 'http://127.0.0.1:9010/files/file/_search?pretty=1' -d '{  "size" : 0,  "query":{    "match":{      "fileName":"brown"    }  },  "aggregations" : {    "docs" : {      "top_hits" : {        "highlight": {          "fields": {            "fileName": {}          }        }      }    }  }}'