Not able to use scripting_field to show distance: ES_6.1

Hi I am new to Elastic search. I want to show distance in result while using "_search" where "location" field is of type : geopoint; I found we can use script_fields but this is not working.
To mention : I am using 6.1 ES version.

    {
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "200km",
                    "location" : {
                        "lat" : 28.6139,
                        "lon" : 77.209
                    }
                }
            }
        }
    },
  "script_fields" : {
      "distance" : {
         "lang": "painless",
         "params" : {
            "lat" : 47.1,
            "lon" : 8.1
         },
         "script" : "doc['location'].DistanceInKm(lat,lon)"
      }
   }
        
    }
"error": {
    "root_cause": [
        {
            "type": "parsing_exception",
            "reason": "Unknown key for a VALUE_STRING in [lang].",
            "line": 20,
            "col": 18
        }
    ],
    "type": "parsing_exception",
    "reason": "Unknown key for a VALUE_STRING in [lang].",
    "line": 20,
    "col": 18
},
"status": 400

}

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.