# Elastic search order of the highlighted fields not matching with the ranking

**URL:** <https://discuss.elastic.co/t/elastic-search-order-of-the-highlighted-fields-not-matching-with-the-ranking/341889>\
**Category:** Elasticsearch\
**Created:** [August 29, 2023, 2:19pm UTC](https://discuss.elastic.co/t/elastic-search-order-of-the-highlighted-fields-not-matching-with-the-ranking/341889 "2023-08-29T14:19:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_Jadhav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikram_jadhav/32/125057_2.png) [@Vikram\_Jadhav](https://discuss.elastic.co/u/Vikram_Jadhav)\
**Post date:** [August 29, 2023, 2:19pm UTC](https://discuss.elastic.co/t/elastic-search-order-of-the-highlighted-fields-not-matching-with-the-ranking/341889/1 "2023-08-29T14:19:23Z")

</div>

Hello,

In the below document, I am trying to match multiple fields and I also want to know what fields are getting matched from the document that's why used the highlighted fields.

sample doc:

```auto
{
	"therapeutic_area": "pain management",
	"indications": [
	        "Dental conditions",
            "Dental pain",
            "Neurological conditions",
            "Pain management",
            "Acute and chronic pain",
            "Pre/Post surgical pain"
	]
}

```

query:

```auto
"query": {
    "multi_match": {
      "query": "dental pain",
      "type": "best_fields",
      "fields": [
        "therapeutic_area",
        "indications",
      ]
    }
  },
  "highlight": {
    "fields": [
      {
        "therapeutic_area": {}
      },
      {
        "indications": {}
      }
    ]
  }

```

and the highlighted result that I got is like below

```auto
"highlight": {
          "therapeutic_area": [
            "Trauma/Pain management"
          ],
          "indications": [
            "Dental conditions",
            "Dental pain",
            "Pain management",
            "Acute and chronic pain",
            "Pre/Post surgical pain"
          ]
        }

```

now the problem here is while I am looping over the keys from highlight field (therapeutic\_area, indications) I am not able to get the rankings properly as therapeutic\_area, indications are does not follow the rankings.

my question is how can I get proper rankings in the highlighted field?

---

<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:** [September 26, 2023, 2:20pm UTC](https://discuss.elastic.co/t/elastic-search-order-of-the-highlighted-fields-not-matching-with-the-ranking/341889/2 "2023-09-26T14:20:03Z")

</div>

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