Gilles GNANAGBE
Gilles GNANAGBE

Reputation: 41

Elastich search sorting by location distance, "Sort direction ' is not 'asc' or 'desc'"

{ "query": "", "page": { "size": 18 }, "filters": { "all": [ { "published": "1" }, { "psid": "58" } ] }, "sort": [ { "geopoint": { "pin.location": [ 4.342083917809, -2.9475302108444 ], "order": "asc", "unit": "km", "mode": "min", "distance_type": "arc", "ignore_unmapped": true } } ] }

i'm receiving error like this :

{
"errors": [
    "Sort direction '{\"pin.location\"=>[4.342083917809, -2.9475302108444], \"order\"=>\"asc\", \"unit\"=>\"km\", \"mode\"=>\"min\", \"distance_type\"=>\"arc\", \"ignore_unmapped\"=>true}' is not 'asc' or 'desc'"
]

}

I do not understand. Please need help.

Upvotes: 1

Views: 113

Answers (2)

Rama Salahat
Rama Salahat

Reputation: 212

you should be using _geo_distance instead of geopoint, this is how it should be according to the official docs:

"sort" : [
    {
        "_geo_distance" : {
            "pin.location" : [-70, 40],
            "order" : "asc",
            "unit" : "km",
            "mode" : "min",
            "distance_type" : "arc",
            "ignore_unmapped": true
        }
    }
],

Upvotes: 0

ilvar
ilvar

Reputation: 5841

It should be called _geo_distance not geopoint, see example in the docs

Upvotes: 1

Related Questions