# Return other fields in highlight

**URL:** https://discuss.elastic.co/t/return-other-fields-in-highlight/300898
**Category:** Elasticsearch
**Created:** [March 29, 2022, 12:52am UTC](https://discuss.elastic.co/t/return-other-fields-in-highlight/300898 "2022-03-29T00:52:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![matty\_r](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@matty\_r](https://discuss.elastic.co/u/matty_r)
#### Post date: [March 29, 2022, 12:52am UTC](https://discuss.elastic.co/t/return-other-fields-in-highlight/300898/1 "2022-03-29T00:52:06Z")

</div>

Hi all,

When highlighting a field, i'd like to also return both fields that are associated. I have the setup below. I want to highlight comment.message, but return both comment.message and comment.id:

```auto
PUT temp-test
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "comment": {
        "properties": {
          "id": {
            "type": "keyword"
          },
          "message": {
            "type": "text"
          }
        }
      }
    }
  }
}

POST temp-test/_doc
{
  "title": "here is my document title",
  "comment": [{
    "id": "1",
    "message": "highlight title in the message but return the id also"
  },
  {
    "id": "2",
    "message": "dont highlight this one"
  }]
}

GET temp-test/_search
{
  "query": {
    "match": {
      "title": "title"
    }
  },
  "highlight": {
    "pre_tags": [
      "<b>"
    ],
    "post_tags": [
      "</b>"
    ],
    "require_field_match": false,
    "fields": {
      "comment.message": {}
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![lucasbemol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lucasbemol/32/69597_2.png) [@lucasbemol](https://discuss.elastic.co/u/lucasbemol)
#### Post date: [March 29, 2022, 3:52pm UTC](https://discuss.elastic.co/t/return-other-fields-in-highlight/300898/2 "2022-03-29T15:52:13Z")

</div>

Hi,  
I have the same problem, did you find a solution?

---

<div class="post-metadata">

### Author: ![matty\_r](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@matty\_r](https://discuss.elastic.co/u/matty_r)
#### Post date: [March 29, 2022, 9:55pm UTC](https://discuss.elastic.co/t/return-other-fields-in-highlight/300898/3 "2022-03-29T21:55:56Z")

</div>

No, nothing yet. I'm looking into setting matched\_fields and using a highlight\_query, so far I haven't been successful - but I think this would probably be the only way to achieve it (from what i've seen).

---

<div class="post-metadata">

### Author: ![matty\_r](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@matty\_r](https://discuss.elastic.co/u/matty_r)
#### Post date: [March 29, 2022, 10:28pm UTC](https://discuss.elastic.co/t/return-other-fields-in-highlight/300898/5 "2022-03-29T22:28:07Z")

</div>

Thought I fixed it, but it didn't return the correct id. Might change behaviour if it's a nested 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: [April 26, 2022, 10:28pm UTC](https://discuss.elastic.co/t/return-other-fields-in-highlight/300898/6 "2022-04-26T22:28:37Z")

</div>

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