Book Image

ElasticSearch Blueprints

Book Image

ElasticSearch Blueprints

Overview of this book

Table of Contents (15 chapters)
Elasticsearch Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Sorting results


Sometimes, you may want to provide the user with a result set that is sorted based on a custom logic rather than the default scoring employed by Elasticsearch. Say you want to display some items that match your search query sorted according to the prize in the ascending or descending order. Elasticearch helps you do that quite easily. Let's see how various sort methods are used in Elasticsearch.

One thing that we should keep in mind while sorting is that the particular field based on which you sort, should be loaded in the memory. It's well and good if you have enough resources to sort. Sort is basically done on the field level. Elasticsearch provides support to perform sorting on arrays or multivalued fields.

However, if the sort field is an array or has multivalues, you can use any of the following functions to combine the result of these values in a single document to yield the sort value of that document:

  • min

  • max

  • sum

  • avg

As the name indicates, min picks the lowest value...