elasticsearch/elasticsearch — pull request #4400 by rboulton (2013-12-10 14:01:17+00:00)
Title: Fix bug in explain for function_score queries.

The explain output for function_score queries with score_mode=max or
score_mode=min was incorrect, returning instead the value of the last
function. This change fixes this.

For example, for the query:

{
"explain": true,
"query": {
"function_score": {
"query": {
"match_all": {}
},
"score_mode": "max",
"functions": [
{
"boost_factor": 1
},
{
"boost_factor": 3
},
{
"boost_factor": 2
}
]
}
}
}

Results are returned containing

hits: [
{
_score: 3,
...
_explanation: {
value: 2
...
}
]

Similarly, if "score_mode": "min" is used, the value in the explanation is still 2.

I would expect the value in _explanation object to be the same as the _score value, and with this patch applied it is.