4
votes

Refering to the documentation of Sorting, section Geo Distance Sorting, here's the question:

The given example is as follows:

GET /_search
{
    "sort" : [
        {
            "_geo_distance" : {
                "pin.location" : [-70, 40],
                "order" : "asc",
                "unit" : "km",
                "mode" : "min",
                "distance_type" : "sloppy_arc"
            }
        }
    ],
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

Is pin.location the field in the mapping containing the geo location? Or is it a keyword understood by the search API as including the base location? If it's a field supposedly containing the location, shouldn't the sort term include the nested_path set to pin? And if it's a parameter, where does elasticsearch fetch the location of the item from?

Also, the documentaion mentions sort_mode as a parameter, but the code uses mode, I suppose that's a typo?

1

1 Answers

2
votes

pin.location is the name of field containing the location to sort against.

nested_path is not needed if pin is a simple object, i.e. not a nested one.

Both mode and sort_mode are correct names, however, sort_mode is deprecated, so mode should be preferred.