elasticsearch icon indicating copy to clipboard operation
elasticsearch copied to clipboard

geo sort

Open nchankov opened this issue 10 years ago • 1 comments

Hi,

I am wondering how can I use sort by distance? if I set parameter "sort" make it like:

{..., "sort"=>array("name", "id")}

it works ok, but I have a location field which is mapped as "geo_point" but when I add in that array "location" the results disappear, and I guess there is an error underneath (meaning the response from the ES, not your lib)?

Any ideas?

Thank you

nchankov avatar Dec 20 '13 10:12 nchankov

I had the same problem. This is what I used:

'sort' => array(
                    array(
                        '_geo_distance' => array(
                            'location' => array(
                                'lat' => $this->latitude,
                                'lon' => $this->longitude,
                            ),
                            'order' => 'asc',
                            'unit' => 'km'
                        ),
                    ),
                ),

garethwi avatar Mar 12 '15 09:03 garethwi