Return other fields in highlight

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:

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": {}
    }
  }
}
1 Like

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

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).

Thought I fixed it, but it didn't return the correct id. Might change behaviour if it's a nested field.

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