简体   繁体   中英

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

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": {}
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM