Sorting results
When searching for results, the standard criterion for sorting in Elasticsearch is the relevance to a text query. Often, real-world applications need to control the sorting criteria in scenarios, such as the following:
- Sorting a user by their last name and their first name
- Sorting items by stock symbols and price (ascending and descending)
- Sorting documents by size, file type, source, and more
- Sorting items related to the maximum, the minimum, or the average of some of the children fields
Getting ready
You will need an up-and-running Elasticsearch installation, as described in the Downloading and installing Elasticsearch recipe of Chapter 1, Getting Started.
To execute these commands, any HTTP client can be used, such as Curl (https://curl.haxx.se/), Postman (https://www.getpostman.com/), or similar. I suggest using the Kibana console as it provides code completion and better character escaping for Elasticsearch.
To correctly execute...