-
Notifications
You must be signed in to change notification settings - Fork 24.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support geo sorting on multiple geo point values per doc #1846
Comments
While waiting for this enhancement, I've managed to get this working using the scripting functionality of ElasticSearch (which I have to say is utterly awesome, this is such a refreshing API to work with). The following solution is very rough. It currently only supports kilometers and the A temporary solutionI have the following javascript in
Then, in my search body, I have something like:
Hopefully someone will find this useful. |
jest sewz you know dominic: ESP dev centre left geo-location searching b. On 09/07/2012 05:48 PM, Dominic Watson wrote:
|
I would also very much like to see this implemented. |
As a response to @DominicWatson: (function(){
var i, locations, arcDist, closest, distance;
arcDist = function( lat1, lat2, lon1, lon2 ){
var R = 6371 // earth radius
, CI = 0.017453292519943295 // pi/180
, dLat = (lat2-lat1) * CI / 2
, dLon = (lon2-lon1) * CI / 2
, sinDLat = Math.sin(dLat)
, sinDLon = Math.sin(dLon)
, a = sinDLat*sinDLat + sinDLon*sinDLon * Math.cos(lat1*CI)*Math.cos(lat2*CI)
, c = 2*Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
locations = doc["locations"].getValues();
closest = arcDist( lat, locations[0].lat(), lon, locations[0].lon() );
for( i=1; i < locations.length; i++ ) {
distance = arcDist( lat, locations[i].lat(), lon, locations[i].lon() );
if(distance < closest) {
closest = distance;
}
}
return closest;
})(); |
The next 0.90 release will have a |
# By Igor Motov (1) and Martijn van Groningen (1) # Via Marco Simons (1) and Martijn van Groningen (1) * 'master' of https://github.com/msimons/elasticsearch: Added sort mode to geo distance sorting. Closes elastic#1846 Fix LeastUsedDistributor and ensure random distribution for multiple non-fs directories
Does this question have new solution which is not rough, now |
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
The text was updated successfully, but these errors were encountered: