Reputation: 686
The following Query in the elasticsearch will give results located within the specified distance. The result doesn't includes the actual distance. Is there any way to get this information in elasticsearch ?
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "12km",
"pin.location" : [-70, 40]
}
}
}
}
Upvotes: 2
Views: 3331
Reputation: 16925
Use a script field with the same reference point as in the geo_distance
filter. Full query:
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "5000km",
"pin.location": [
-70,
40
]
}
}
}
},
"script_fields": {
"distance_in_m": {
"script": "doc['pin.location'].arcDistance(40, -70)"
}
}
}
OR
geo-sort and you'll get the distance info included in the sort response.
Upvotes: 3