Elasticsearch: unified highlighter not applied when used in combination with function_score

Viewed 22

The following query doesn't return a highlight property in the response:

GET /my_index/_search?rest_total_hits_as_int=true
{
  "size": 1,
  "from": 0,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "match_phrase_prefix": {
                "fullNames": { "query": "si", "max_expansions": 300, "boost": 2 }
              }
            }
          ]
        }
      },
      "functions": [
        {
          "field_value_factor": {
            "field": "articleCount",
            "modifier": "log1p",
            "factor": 0.5,
            "missing": 1
          }
        }
      ],
      "boost_mode": "sum",
      "score_mode": "sum"
    }
  },
  "highlight": {
    "fields": {
      "fullNames": {
        "number_of_fragments": 0,
        "type": "unified"
      }
    }
  }
}

The highlight property does appear when I do one of the following:

  • I use the query without the function_score
  • I change the highlighter from unified to plain

I cannot find anything about this in the documentation, which makes me think its a bug that occurs when using the combination of function chain and the unified highlighter.

On a side note:

I actually stumbled upon this problem when upgrading from 6.8 to 7.17. With version 6.8 I did get the highlight property. I am not sure if that's the case because the problem didn't exist in 6.8 or because I didn't explicitly set the type of the highlighter so it may have used a different default highlighter in 6.8 than in 7.17. In the documentation of 6.8 I cannot find what the default highlighter is. I also don't see anything in the breaking changes that explain a change in behaviour.

0 Answers
Related