Using a function score query
This kind of query is one of the most powerful queries available, because it allows extensive customization. The function score query allows you 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 requires a lot of memory, but computing them in a small subset can significantly improve the search quality.
These are the common scenarios used for this query:
Creating a custom score function (for example with the decay function)
Creating a custom boost factor, for example, based on another field (such as boosting a document by its distance from a point)
Creating a custom filter score function, for example based on scripting ElasticSearch capabilities
Ordering the documents randomly
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (chapter_05/populate_query.sh
) available in the code bundle for this book.