Getting the distance back in geo_distance queries


(Diptamay) #1

Hi

I am trying out the geo search features of ES. So I ran the following
query.
curl -XGET 'http://localhost:9200/activities/69482975/_search?
pretty=true' -d '
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"geo.coordinate" : "45.53226,-122.68145"
}
}
}
},
"size" : 5
}
}'

Is there any way, I could get the calculated distance from the point
(geo.coordinate) being searched on, in the search results and sort by
that calculated distance, much like the geodist function in Solr
spatial search.

Thanks
Diptamay


(Shay Banon) #2

Yes, you can sort by geo distance: http://www.elasticsearch.org/guide/reference/api/search/sort.html. You will also get the values back.

-shay.banon
On Wednesday, March 23, 2011 at 4:50 AM, diptamay wrote:

Hi

I am trying out the geo search features of ES. So I ran the following
query.
curl -XGET 'http://localhost:9200/activities/69482975/_search?
pretty=true' -d '
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"geo.coordinate" : "45.53226,-122.68145"
}
}
}
},
"size" : 5
}
}'

Is there any way, I could get the calculated distance from the point
(geo.coordinate) being searched on, in the search results and sort by
that calculated distance, much like the geodist function in Solr
spatial search.

Thanks
Diptamay


(system) #3