'highlight in elasticsearch query? how to highlight two fields?

my search field is one ,but I need to highlight two fields in a document? how can I achieve this Ex: my search query is match:{"file":"hello"} I want to highlight email field also



Solution 1:[1]

You need to set require_field_match value to false as by default, only fields that contains a query match are highlighted.

{
  "query": {
    "match": {
      "file": "hello"
    }
  },
  "highlight": {
    "require_field_match": "false",
    "fields": {
      "title": {},
      "email": {}
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sagar Patel