I was trying to use arcDistance using the following:
PUT /my_locations
{
"mappings": {
"location": {
"properties": {
"pin": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
}
}
PUT /my_locations/location/1
{
"pin" : {
"location" : {
"lat" : 40.12,
"lon" : -71.34
}
}
}
GET /my_locations/location/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
},
"script_fields": {
"closest_listing" : {
"script": {
"lang": "painless",
"inline": "return params._source.pin.location.arcDistance(40.0,-72.0)"
}
}
}
}
when I execute the query I get
{
"took": 32,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 4,
"failed": 1,
"failures": [
{
"shard": 3,
"index": "my_locations",
"node": "4Ts84JXZTiCaQjSx-7q7MQ",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Unable to find dynamic method [arcDistance] with [2] arguments for class [java.util.HashMap]."
},
"script_stack": [
"return params._source.pin.location.arcDistance(40.0,-72.0)",
" ^---- HERE"
],
"script": "return params._source.pin.location.arcDistance(40.0,-72.0)",
"lang": "painless"
}
}
]
},
"hits": {
"total": 1,
"max_score": 1,
"hits": []
}
}
Is it possible to calculate the distance using _source? I need to because I store multiple geo_points in an array per document and want to calculate the closest distance.