Geo point distance with multiple locations in array

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)

Here is the link for curl queries and data: Sorting geopoints in array · GitHub

On Jul 19, 7:48 pm, sakaraut 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)

Sort has little meaning when there are multiple values, so its not really
aimed at solving that. If you want specific location to sort on, then index
it separately.

On Tue, Jul 19, 2011 at 7:50 PM, sakaraut sakari.rautiainen@gmail.comwrote:

Here is the link for curl queries and data:
Sorting geopoints in array · GitHub

On Jul 19, 7:48 pm, sakaraut 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)