Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Geo Distance Range Filter

More info about geo distance range filter is in the official elasticsearch docs

Filters documents that exists within a range from a specific point.

Simple example

{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance_range" : {
                "from" : "200km",
                "to" : "400km",
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

And now the query via DSL:

$geoDistanceRangeFilter = new GeoDistanceRangeFilter(
    'pin.location',
    ['from' => '200km', 'to' => '400km'],
    ['lat' => 40, 'lon' => -70]
);

$search = new Search();
$search->addFilter($geoDistanceRangeFilter);

$queryArray = $search->toArray();