# Highlight not working properly

**URL:** <https://discuss.elastic.co/t/highlight-not-working-properly/307128>\
**Category:** Elasticsearch\
**Created:** [June 14, 2022, 10:05am UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128 "2022-06-14T10:05:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil5](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Sahil5](https://discuss.elastic.co/u/Sahil5)\
**Post date:** [June 14, 2022, 10:05am UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/1 "2022-06-14T10:05:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 14, 2022, 11:20pm UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/2 "2022-06-14T23:20:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sahil5](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Sahil5](https://discuss.elastic.co/u/Sahil5)\
**Post date:** [June 15, 2022, 5:27am UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/3 "2022-06-15T05:27:34Z")

</div>

Hi Below is the query i am using

```auto
{
  "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"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

```auto
{
  "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.

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

```

---

<div class="post-metadata">

**Author:** ![Sahil5](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Sahil5](https://discuss.elastic.co/u/Sahil5)\
**Post date:** [June 17, 2022, 6:10am UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/4 "2022-06-17T06:10:13Z")

</div>

Hi Team,

Any idea about above issue?

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 20, 2022, 7:05am UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/5 "2022-06-20T07:05:32Z")

</div>

The document says:

> Highlighters don’t reflect the boolean logic of a query when extracting terms to highlight.  
> [Highlighting | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html)

The highlighting over boolean query may not be supported.

---

<div class="post-metadata">

**Author:** ![Sahil5](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@Sahil5](https://discuss.elastic.co/u/Sahil5)\
**Post date:** [June 20, 2022, 10:03am UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/6 "2022-06-20T10:03:04Z")

</div>

Hi @Tomo_M,

Do you have any idea how to solve this problem?

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 20, 2022, 12:23pm UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/7 "2022-06-20T12:23:52Z")

</div>

What will happen if you specify more simple unnested boolean query as [highlight query](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html#specify-highlight-query)? I have no idea other than this.

---

<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:** [July 18, 2022, 12:23pm UTC](https://discuss.elastic.co/t/highlight-not-working-properly/307128/8 "2022-07-18T12:23:55Z")

</div>

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