June 2017
Beginner to intermediate
404 pages
8h 22m
English
In this section, we will discuss how to sort the results by the distance to the given location. In most cases, scoring the results like we did in the Geo Distance query section is a better option than sorting the results. The real power of Elasticsearch is combining the different type of queries and assigning weights to each query. The query to sort all the stores based on the distance from the current location is shown here:
#GEO Sort POST chapter7/store/_search { "query": { "match_all": {} }, "sort": [ { "_geo_distance": { "location": { "lat": "37.348929", "lon": "-121.888536" }, "order": "asc", "unit" : "mi" } } ] }
In the preceding query, the result is sorted in ascending ordering of the distance from the given location. And ...
Read now
Unlock full access