# Highlighting two fields while query one field

**URL:** <https://discuss.elastic.co/t/highlighting-two-fields-while-query-one-field/210223>\
**Category:** Elasticsearch\
**Created:** [December 2, 2019, 5:26pm UTC](https://discuss.elastic.co/t/highlighting-two-fields-while-query-one-field/210223 "2019-12-02T17:26:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shani\_angarkadu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shani_angarkadu/32/50638_2.png) [@shani\_angarkadu](https://discuss.elastic.co/u/shani_angarkadu)\
**Post date:** [December 2, 2019, 5:26pm UTC](https://discuss.elastic.co/t/highlighting-two-fields-while-query-one-field/210223/1 "2019-12-02T17:26:01Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [December 3, 2019, 5:43pm UTC](https://discuss.elastic.co/t/highlighting-two-fields-while-query-one-field/210223/2 "2019-12-03T17:43:51Z")

</div>

You can [set `require_field_match` to `false`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#highlighting-settings) in order to achieve that:

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

```

---

<div class="post-metadata">

**Author:** ![shani\_angarkadu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shani_angarkadu/32/50638_2.png) [@shani\_angarkadu](https://discuss.elastic.co/u/shani_angarkadu)\
**Post date:** [December 3, 2019, 9:26pm UTC](https://discuss.elastic.co/t/highlighting-two-fields-while-query-one-field/210223/3 "2019-12-03T21:26:45Z")

</div>

I should have read the document more thoroughly. Thank you

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 31, 2019, 9:26pm UTC](https://discuss.elastic.co/t/highlighting-two-fields-while-query-one-field/210223/4 "2019-12-31T21:26:45Z")

</div>

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