# Geo point distance with multiple locations in array

**URL:** <https://discuss.elastic.co/t/geo-point-distance-with-multiple-locations-in-array/4897>\
**Category:** Elasticsearch\
**Created:** [July 19, 2011, 4:48pm UTC](https://discuss.elastic.co/t/geo-point-distance-with-multiple-locations-in-array/4897 "2011-07-19T16:48:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sakaraut](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@sakaraut](https://discuss.elastic.co/u/sakaraut)\
**Post date:** [July 19, 2011, 4:50pm UTC](https://discuss.elastic.co/t/geo-point-distance-with-multiple-locations-in-array/4897/2 "2011-07-19T16:50:05Z")

</div>

Here is the link for curl queries and data: [Sorting geopoints in array · GitHub](https://gist.github.com/1093017)

On Jul 19, 7:48 pm, sakaraut [sakari.rautiai...@gmail.com](mailto:sakari.rautiai...@gmail.com) wrote:

> I am trying to sort items which have location array. Each item can  
> have more than one location and I am using the following sorting  
> query:  
> {
> 
> ```
> "sort" : [
> {
> "_geo_distance" : {
> "pin.location" : [60, 20],
> "order" : "asc",
> "unit" : "km"
> }
> }
> ],
> 
> ```
> 
> "query": {"match\_all": {}}
> 
> }'
> 
> Then I read the "sort" value to get distance of item location's to the  
> given location(lat:20,long:60). This works correctly if the item has  
> only one location but if there is more than one as in here:  
> {  
> "message" : "Locations",  
> "pin": {  
> "location": [[60,20],[50,20]]  
> }}
> 
> The "sort" value becomes 1045.90911935061 not 0.0 as expected. It  
> doesn't matter if I am using desc or asc as the sorting order, but it  
> still gives the same output and calculates the distance from the last  
> array item.
> 
> Is there a way to get the distance to the closest location from that  
> array and sort items using some other query?  
> (Other than create index entries for each location)

---

_[View the full topic](https://discuss.elastic.co/t/geo-point-distance-with-multiple-locations-in-array/4897)._
