# Highlighting not working after upgrade

**URL:** <https://discuss.elastic.co/t/highlighting-not-working-after-upgrade/312095>\
**Category:** Elasticsearch\
**Created:** [August 15, 2022, 11:50am UTC](https://discuss.elastic.co/t/highlighting-not-working-after-upgrade/312095 "2022-08-15T11:50:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![henke71](https://avatars.discourse-cdn.com/v4/letter/h/cdc98d/32.png) [@henke71](https://discuss.elastic.co/u/henke71)\
**Post date:** [August 15, 2022, 11:50am UTC](https://discuss.elastic.co/t/highlighting-not-working-after-upgrade/312095/1 "2022-08-15T11:50:38Z")

</div>

Highlighting has stopped working after upgrade from 7.16 to 8.3.3  
This is when using must\_not.

**Steps to reproduce**

Create index

```auto
PUT /test
{
  "mappings": {
    "properties": {
      "Name": { "type": "text" },
      "HideIfThisFieldIsSet": { "type": "text" }
    }
  }
}

POST test/_doc
{
  "Name": "Kalle",
  "HideIfThisFieldIsSet": null
}

POST test/_doc
{
  "Name": "Kalle",
  "HideIfThisFieldIsSet": "Hide"
}

```

Execute the following query

```auto
GET test/_search
{
  "highlight": {
    "fields": {
      "Name": {}
    }
  },
  "query": {
    "bool": {
      "must_not": [{"exists": {"field": "HideIfThisFieldIsSet"}}],
      "must": [
        {
          "multi_match": {
            "fields": ["Name"],
            "query": "Kalle"
          }
        }
      ]
    }
  }
}

```

One hit as expected but no highlighting in result

```auto
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.18232156,
    "hits": [
      {
        "_index": "test",
        "_id": "NABMoYIB7nqUcjsQG75h",
        "_score": 0.18232156,
        "_source": {
          "Name": "Kalle",
          "HideIfThisFieldIsSet": null
        }
      }
    ]
  }
}

```

Remove the must\_not clause

```auto
GET test/_search
{
  "highlight": {
    "fields": {
      "Name": {}
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "fields": ["Name"],
            "query": "Kalle"
          }
        }
      ]
    }
  }
}

```

Two hits and highlighting as expected

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 0.18232156,
    "hits": [
      {
        "_index": "test",
        "_id": "NABMoYIB7nqUcjsQG75h",
        "_score": 0.18232156,
        "_source": {
          "Name": "Kalle",
          "HideIfThisFieldIsSet": null
        },
        "highlight": {
          "Name": [
            "<em>Kalle</em>"
          ]
        }
      },
      {
        "_index": "test",
        "_id": "NQBMoYIB7nqUcjsQQb5N",
        "_score": 0.18232156,
        "_source": {
          "Name": "Kalle",
          "HideIfThisFieldIsSet": "Hide"
        },
        "highlight": {
          "Name": [
            "<em>Kalle</em>"
          ]
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![henke71](https://avatars.discourse-cdn.com/v4/letter/h/cdc98d/32.png) [@henke71](https://discuss.elastic.co/u/henke71)\
**Post date:** [August 31, 2022, 1:17pm UTC](https://discuss.elastic.co/t/highlighting-not-working-after-upgrade/312095/2 "2022-08-31T13:17:35Z")

</div>

This is a confirmed bug and will hopefully be solved.  
A workaround is to add "type":"plain" in the highlight section.

---

<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 28, 2022, 1:18pm UTC](https://discuss.elastic.co/t/highlighting-not-working-after-upgrade/312095/3 "2022-09-28T13:18:06Z")

</div>

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