Using the function score query
This kind of query is one of the most powerful queries that are available. This is because it allows extensive customization of a scoring algorithm. The function_score
query allows us to define a function that controls the score of the documents that are returned by a query.
Generally, these functions are CPU-intensive, and executing them on a large dataset (for instance, millions of records) requires a lot of memory and time, but computing them on a small subset can significantly improve the search quality.
The common scenarios used for this query are listed as follows:
- Creating a custom score function (for example, with the decay function)
- Creating a custom boost factor, for example, based on another field (that is, boosting a document by distance from a point)
- Creating a custom filter score function, for example, based on scripting Elasticsearch capabilities
- Ordering the documents randomly
Getting ready
You will...