I'm getting this error when trying to match all in my index, and display the distance between a given geo_point and the query results, I'm using DrTech's answer for the script to display the distance:
this is my DSL query:
{
"query": {
"match_all": {}
},
"script_fields": {
"distance": {
"lang": "groovy",
"params": {
"lat": 2.27,
"lon": 50.3
},
"script": "doc['geo_coordinates'].distanceInKm(lat,lon)"
}
}
}
Query response:
{
"took": 50,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 4,
"failed": 1,
"failures": [
{
"shard": 0,
"index": "users",
"node": "pa76fjdWQl2YAHmgCT4oKw",
"reason": {
"type": "script_exception",
"reason": "failed to run inline script [doc['geo_coordinates'].distanceInKm(lat,lon)] using lang [groovy]",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"hits": {
"total": 184,
"max_score": 1,
"hits": []
}
and I have this in my mapping :
"geo_coordinates" : {
"type" : "geo_point",
"lat_lon" : true
},
so I don't understand why I'm getting a Null pointer !! .....
geo_coordinates
field ? – ValdistanceInKm()
if the value exists. – Val