I have multiple geo points per document and would like to be able to sort based on the closest matching location in the document to my center point. Apparently the way things currently work is the sort will be based on a random location on the document, as in the following scenario:
$ 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 ]
}
...
office8 and office3 both 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).
I have multiple geo points per document and would like to be able to sort based on the closest matching location in the document to my center point. Apparently the way things currently work is the sort will be based on a random location on the document, as in the following scenario:
I have the following mapping:
Then I have the following query and response (I've only included hits to cut down on noise):
office8 and office3 both 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).
This was originally discussed here: https://groups.google.com/forum/?fromgroups#!topic/elasticsearch/DxIUevwZfOs