Controlling scores using the function score query
In most cases, you are good to go with the default scoring algorithms of Elasticsearch to return the most relevant results. However, some cases require you to have more control over the calculation of a score. This is especially required while implementing domain-specific logics where you need to implement a very specific scoring formula and alter the final score. Elasticsearch provides you with the function_score
query to take control of all these things.
The function_score
query allows you to take complete control of how a score needs to be calculated for a particular query. The syntax of the function_score
query is given as follows:
{ "query": {"function_score": { "query": {}, "boost": "boost for the whole query", "functions": [ {} ], "max_boost": number, "score_mode": "(multiply|max|...)", "boost_mode...