1
votes

Referring to the ES documentation, we can sort on the base of geolocation if lat and lon are both in the same geotype field.

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

In my case, I have the location in separate float fields for both latitude and longitude. How can I sort on geo-distance if I can't change my schema?

1

1 Answers

1
votes

You will need to create a new index with a new mapping which will contain geo point field instead of two fields (lat, long). Then, you need to index data into the newly created index. Have a look into Reindex API - will help you with moving data into the new index.