I am using alias fields to do different highlighting on basically the same field. I use highlight_queries
to highlight different parts of the same field. This worked fine in ES up to 7.9.1 but changed its behaviour in newer versions.
As a minimal example, consider this mapping:
{
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"title": {
"type": "text",
"store": true
},
"title-hl1": {
"type": "alias",
"path": "title"
}
}
}
}
Here is a sample document:
{
"title": "the big brown fox"
}
And, finally, a query for two different highlights using the original field and the alias field:
{
"query": {
"match_all": {}
},
"highlight": {
"fields": {
"title": {
"highlight_query": {
"terms": {
"title":["big"]
}
}
},
"title-hl1": {
"highlight_query": {
"terms": {
"title-hl1":["brown"]
}
}
}
}
}
}
As you can see, I want to highlight different words. In a real-world application I would use this to assign different highlight tags to use on my Web site for different styling.
Now, the response I did expect - and that I actually received as long as I was using Elasticsearch 7.9.1 - looks like this:
{
"_index": "index_alias_fields",
"_id": "-qFL-4QBRhuUbQLaZAeD",
"_score": 1,
"_source": {
"title": "the big brown fox"
},
"highlight": {
"title-hl1": [
"the big <em>brown</em> fox"
],
"title": [
"the <em>big</em> brown fox"
]
}
}
One highlight features the word brown
, the other big
.
But since I updated to newer versions of Elasticsearch, including 7.17.7 and 8.5.3, the response instead looks like this:
{
"_index": "index_alias_fields",
"_id": "-qFL-4QBRhuUbQLaZAeD",
"_score": 1,
"_source": {
"title": "the big brown fox"
},
"highlight": {
"title-hl1": [
"the <em>big</em> brown fox"
],
"title": [
"the <em>big</em> brown fox"
]
}
}
The highlighting will always be the same in newer versions of ES no matter the settings I try. Now I can't tell: Is this a bug or the new desired behaviour? I very much preferred to behaviour up to ES 7.9.1 where I could use the alias fields as separate entities for highlighting. This was my main purpose for using alias fields.
Perhaps you can tell me if I'm doing something wrong or if I indeed stumbled into a bug.
Thanks for any comments and help!