Reputation: 1100
I am receiving different _scores while using different approaches, but I am expecting same results.
First approach is using script_score, multiplying _score with field value, and replacing final _score with calculated one with boost_mode = replace
{
"function_score": {
"query": {
"multi_match": {
"query": "body",
"fields": ["title", "text", "keywords"],
"operator": "and"
}
},
"functions": [{
"script_score": {
"script": {
"lang": "groovy",
"inline": "_score * doc['power'].value"
}
}
}],
"boost_mode": "replace"
}
}
Second one is using script_score return just field value, and letting engine calculate _score by using boost_mode = multiply
{
"function_score": {
"query": {
"multi_match": {
"query": "body",
"fields": ["title", "text", "keywords"],
"operator": "and"
}
},
"functions": [{
"script_score": {
"script": {
"lang": "groovy",
"inline": "doc['power'].value"
}
}
}],
"boost_mode": "multiply"
}
}
Why is query returning different _scores?
Upvotes: 1
Views: 495
Reputation: 16335
The difference in your scores could be because of Query Normalization Factor
The query normalization factor (queryNorm) is an attempt to normalize a query so that the results from one query may be compared with the results of another.
Even though the intent of the query norm is to make results from different queries comparable, it doesn’t work very well. The only purpose of the relevance _score is to sort the results of the current query in the correct order. You should not try to compare the relevance scores from different queries.
Now,
multiply : query score and function score is multiplied
replace : only function score is used, the query score is ignored
When you are using boost_mode=multiply
, the query score is being normalized whereas when you use boost_mode=replace
, the score is being replaced with the function score
, query score is being ignored hence no normalization on query score
Upvotes: 1