Hi everybody,
I'm using elasticsearch for a search functionality on a website. The search must provide a search by distance from a location in an - for example - 25km radius.
That's no problem, I'm using the following elaticsearch query array:
{ "index": "kasd9i9021profiles", "type": "profile", "size": 30, "from": 0, "body": { "query": { "bool": { "filter": { "geo_distance": { "distance": "25km", "distance_type": "sloppy_arc", "_cache": true, "location": { "lat": 48.136833417046, "lon": 11.570900696682 }, "unit": "km" } }, "must": [ { "term": { "published": "1" } }, { "match": { "country": "DE" } }, { "match": { "category_id": "1" } } ] } }, "script_fields": { "distance": { "lang": "groovy", "params": { "lat": 48.136833417046, "lon": 11.570900696682 }, "script": "doc['location'].distanceInKm(lat,lon)" } }, "sort": [ { "upgrade_sort": { "order": "desc" } }, { "has_siegel": { "order": "desc" } }, { "_geo_distance": { "location": { "lat": 48.136833417046, "lon": 11.570900696682 }, "order": "asc", "unit": "km" } } ] }, "fields": [ "_source", "distance" ] }
The value of "upgrade_sort" can be between 0 and 3.
The value of "has_siegel" can be true or false.
The problems are:
- The results are not sorted by distance
- The distance in the result is between 0 and ~30km, not between 0 and 25km.
Is that a bug or a wrong query?