# How to make matched\_fields generic while highlighting - Elasticsearch

**URL:** https://discuss.elastic.co/t/how-to-make-matched-fields-generic-while-highlighting-elasticsearch/157628
**Category:** Elasticsearch
**Created:** [November 21, 2018, 6:11am UTC](https://discuss.elastic.co/t/how-to-make-matched-fields-generic-while-highlighting-elasticsearch/157628 "2018-11-21T06:11:53Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)
#### Post date: [November 21, 2018, 6:11am UTC](https://discuss.elastic.co/t/how-to-make-matched-fields-generic-while-highlighting-elasticsearch/157628/1 "2018-11-21T06:11:53Z")

</div>

Hi all,

I am having duplicity in highlighting as few of my searches are matching in both .keyword and text field as well. So i am trying to employ "matched\_fields" on all such fields.Problem is i don't know these fields at query time and there are too many such fields(around 100) which make my query very huge.

```
  "fields": {
      "field1": {
        "matched_fields": [
          "field1",
          "field1.keyword"
        ]
      },
    "field2": {
            "matched_fields": [
                   "field2",
                     "field2.keyword"
                      ]
      }
    }

```

Is there a way to make this generic? or is there any method that i can employ?

---

<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 19, 2018, 6:12am UTC](https://discuss.elastic.co/t/how-to-make-matched-fields-generic-while-highlighting-elasticsearch/157628/2 "2018-12-19T06:12:00Z")

</div>

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