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

Geo Distance Filter

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

Filters documents that include only hits that exists within a specific distance from a geo point.

Simple example

{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "200km",
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

And now the query via DSL:

$geoDistanceFilter = new GeoDistanceFilter(
    'pin.location',
    '200km',
    ['lat' => 40, 'lon' => -70]
);

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

$queryArray = $search->toArray();