Highlight not working properly

Hi Team,

Can anyone please explain me the flow of highlight in Elasticsearch?

When i am adding multiple queries in should condition then highlight is not returning expected values and when i am trying with single query highlight is returning expected results?

I have also tried to boost query that is returning expected result but even after boosting it is not returning expected results.

Please explain how highlight is working with multiple queries and on what basis it is returing result in highlight.

It's be useful if you could provide some example code showing what you are doing, what you are receiving as responses, and what you are expecting.

Hi Below is the query i am using

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "query_string": {
                  "query": "\"-data output - test\"",
                  "fields": [
                    "currentpagetitle_special.en",
                  ],
                  "boost": 50
                }
              },
              {
                "multi_match": {
                  "query": "-data output - test",
                  "fields": [
                    "currentpagetitle_special.en",
                  ],
                  "boost": 20,
                  "operator": "AND",
                  "type": "cross_fields"
                }
              }
            ]
          }
        }
      ]
    }
  }
}
{
  "highlight": {
    "type": "unified",
    "fragment_size": 750,
    "pre_tags": [
      "<span class='highlight'>"
    ],
    "post_tags": [
      "</span>"
    ],
    "fields": {
      "currentpagetitle.en": {
        "fragment_size": 100,
        "require_field_match": false,
        "order": "none"
      },
      "currentpagetitle_special.en": {
        "fragment_size": 100,
        "order": "score"
      }
    }
  }
}

with this query it is not returning currentpagetitle_special.en field in highlight.

When i am removing query string from above query and only hitting multi-match then it is returning currentpagetitle_special.en field in highlight
Below is the query.

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "multi_match": {
                  "query": "-data output - test",
                  "fields": [
                    "currentpagetitle_special.en"
                  ],
                  "boost": 20,
                  "operator": "AND",
                  "type": "cross_fields"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Hi Team,

Any idea about above issue?

The document says:

Highlighters don’t reflect the boolean logic of a query when extracting terms to highlight.
Highlighting | Elasticsearch Guide [8.11] | Elastic

The highlighting over boolean query may not be supported.

Hi @Tomo_M,

Do you have any idea how to solve this problem?

What will happen if you specify more simple unnested boolean query as highlight query? I have no idea other than this.

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