I have this query in Elasticsearch. It works fine but doesn't sort the results by the distance to the search point.
GET /place_names/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "10km",
"location" : {
"lat" : 64,
"lon" : -22
}
}
}
}
},
"script_fields" : {
"id": {"script": "doc['id']"},
"name": {"script": "doc['name']"},
"type": {"script": "doc['type']"},
"location": {"script": "doc['location']"},
"dist_to_point" : {
"script" : "doc['location'].arcDistance(64, -22)"
}
}
}
I would like to sort the results by "dist_to_point". Is that possible?