Return distance in geo distance query in elastic search 5.x

Viewed 2294

I need to get distance from searched coordinates in elastic search using geo distance query. I tried this

curl -XGET 'http://127.0.0.1:9200/branch-master/master/_search?pretty=1'  -d '
{
   "script_fields" : {
      "distance" : {
         "params" : {
            "lat" : 18.00,
            "lon" : 72.00
         },
         "script" : "doc[\u0027location\u0027].distanceInKm(lat,lon)"
      }
   }
}
'

This is got from Return distance in elasticsearch results?

But this gives me error "unknown key for a start_object in [params]". I am not able understand what this is. Above solution seems to be for quite older version of ES. I am using ES 5.1. In the manual I couldn't find relavant solution for geo distance query. Could someone please help me?

1 Answers
Related