Sorting data

So far we've run our queries and got the results in the order determined by the score of each document. However, it is not enough for all the use cases. It is really handy to be able to sort our results on the basis of the field values. For example, when you are searching logs or time-based data in general, you probably want to have the most recent data first. In addition to that, Elasticsearch allows us to control how the document such be sorted not only using field values, but also using more sophisticated sorting like ones that use scripts or sorting on fields that have multiple values. We will cover all that in this section.

Default sorting

Let's look at the following query that returns all the books with at least one of the specified ...

Get Elasticsearch Server - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.