Sorting data

Now we can build quite complex queries for the whole index, or to part of it, by using filters. We can send these queries to ElasticSearch and analyze the returned data. Until now, this data was organized in the order determined by scoring. This is exactly what we want in most cases. Search should give us the most appropriate documents first. But what can we do if we want to use our search more like a database or set a more sophisticated algorithm for data ordering? Let's check what ElasticSearch can do with sorting.

Default sorting

Let's look at the following query, which returns all the books with at least one of the specified words:

{ "query" : { "terms" : { "title" : [ "crime", "front", "punishment" ], "minimum_match" : 1 } } } ...

Get ElasticSearch Server 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.