Highlighting has stopped working after upgrade from 7.16 to 8.3.3
This is when using must_not.
Steps to reproduce
Create index
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
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
{
"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
GET test/_search
{
"highlight": {
"fields": {
"Name": {}
}
},
"query": {
"bool": {
"must": [
{
"multi_match": {
"fields": ["Name"],
"query": "Kalle"
}
}
]
}
}
}
Two hits and highlighting as expected
{
"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>"
]
}
}
]
}
}