Hello, I am having trouble with the highlight-feature highlighting fields that should not be. This problem only occurs if the search contains a nested query.
I have set require_field_match to true in my search and my ES cluster is using version 9.4.4. I believe this is a bug, but I want to confirm that I'm not doing anything wrong. ![]()
Here is an example index:
PUT test
{
"mappings": {
"properties": {
"num": { "type": "long" },
"str1": { "type": "text" },
"str2": { "type": "text" },
"lst": {
"type": "nested",
"properties": {
"val": { "type": "long" }
}
}
}
}
}
Data:
POST test/_create/1
{
"num": 1,
"str1": "foo",
"str2": "bar",
"lst": [
{ "val": 1 }
]
}
Search:
GET test/_search
{
"highlight": {
"require_field_match": true,
"fields": {
"str1": {},
"str2": {}
}
},
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"filter": [
{
"term": {
"num": 0 // num = 0 does not exist, "foo" should not be highlighted.
}
},
{
"match": {
"str1": "foo"
}
}
]
}
},
{
"match": {
"str2": "bar" // "bar" exists.
}
}
]
}
},
{
// Removing this nested query will correctly only highlight "bar".
"nested": {
"path": "lst",
"query": {
"match": {
"lst.val": 1
}
}
}
}
]
}
}
}
Result:
{
// ...
"hits": [
// ...
"highlight": {
"str1": [
"<em>foo</em>" // "foo" should not be highlighted.
],
"str2": [
"<em>bar</em>"
]
}
}
]
}
}