Hi all
My geo_distance sort is not returning things in the order I'd expect. Am I
doing something silly?
I have the following mapping:
$ curl -XGET 'http://localhost:9200/work/offices/_mapping?pretty=true'
{
"offices" : {
"properties" : {
"location" : {
"properties" : {
"address" : {
"type" : "string"
},
"point" : {
"type" : "geo_point"
}
}
},
"name" : {
"type" : "string"
}
}
}
}
Then I have the following query and response (I've only included hits to
cut down on noise):
$ curl -XGET 'http://localhost:9200/work/offices/_search?pretty=true' -d '{
"fields": [ "name", "location" ], "query": { "match_all": {} }, "sort": {
"_geo_distance": {"location.point": [-0.0976398, 51.4962307], "order":
"asc", "unit": "km"} }}'
...
"hits" : [ {
"_index" : "work",
"_type" : "offices",
"_id" : "IDtt2WnSQnWEhuAxhlbPgw",
"_score" : null,
"fields" : {
"location" : [ {
"point" : [ -0.01655, 51.5007324 ],
"address" : "E14 9SH"
}, {
"point" : [ -0.0976398, 51.4962307 ],
"address" : "SE1 6PL"
} ],
"name" : "office3"
},
"sort" : [ 0.0 ]
}, {
"_index" : "work",
"_type" : "offices",
"_id" : "xzaVAHUoSGON8gY1-ggILQ",
"_score" : null,
"fields" : {
"location" : [ {
"point" : [ -0.01655, 51.5007324 ],
"address" : "E14 9SH"
}, {
"point" : [ -0.0684337, 51.4843866 ],
"address" : "SE1 5BA"
} ],
"name" : "office10"
},
"sort" : [ 2.413161036894697 ]
}, {
"_index" : "work",
"_type" : "offices",
"_id" : "ZWjuiVkWSD6H99ooKcKNuA",
"_score" : null,
"fields" : {
"location" : [ {
"point" : [ -0.0976398, 51.4962307 ],
"address" : "SE1 6PL"
}, {
"point" : [ -0.0684337, 51.4843866 ],
"address" : "SE1 5BA"
} ],
"name" : "office8"
},
"sort" : [ 2.413161036894697 ]
}
...
Specifically both office8 and office3 have locations 0km away from my
search point, yet office10 is sneaking in between the two at 2.4km away and
office8 is also placing itself 2.4km away (which it is, but but only on the
further location point). It's as if it only looks at the last geo_point in
the location array.