Highlighting two fields while query one field

I am trying to highlight the match words on two fields while the query searches on 1 filed.

for example, if I search for cancer in terms, I want the highlight in both terms and another filed pref_terms.

{
  "highlight": {
    "fields": [
      {"terms" :{}},
      {"pref_terms" :{}}
    ]
  },
  "query": {
          "bool": {
            "must": [
              {
                "match": {
                  "terms": {
                    "query": "cancer "
                  }
                }
              }
      ]
    }
  },
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}  

You can set require_field_match to false in order to achieve that:

{
  "highlight": {
    "fields": [
      {
        "terms": {}
      },
      {
        "pref_terms": {}
      }
    ],
    "require_field_match": false
  },
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "terms": {
              "query": "cancer "
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
} 
1 Like

I should have read the document more thoroughly. Thank you

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.