Skip to content

Latest commit

 

History

History
128 lines (93 loc) · 3.28 KB

geo-queries.md

File metadata and controls

128 lines (93 loc) · 3.28 KB

Geo Queries

Geo-Distance

You can use Elastic\ScoutDriverPlus\Support\Query::geoDistance() to build a geo-distance query:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70);

$searchResult = Store::searchQuery($query)->execute();

Available methods:

distanceType

distanceType defines how to compute the distance:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70)
    ->distanceType('plane');

$searchResult = Store::searchQuery($query)->execute();

distance

Use distance to set the radius of the circle centred on the specified location:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70);

$searchResult = Store::searchQuery($query)->execute();

field

Use field to specify the field, which represents the geo point:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70);

$searchResult = Store::searchQuery($query)->execute();

ignoreUnmapped

You can use ignoreUnmapped to query multiple indexes which might have different mappings:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70)
    ->ignoreUnmapped(true);

$searchResult = Store::searchQuery($query)->execute();

lat

lat defines the geo point latitude:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70);

$searchResult = Store::searchQuery($query)->execute();

lon

lon defines the geo point longitude:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70);

$searchResult = Store::searchQuery($query)->execute();

validationMethod

validationMethod defines how latitude and longitude are validated:

$query = Query::geoDistance()
    ->field('location')
    ->distance('200km')
    ->lat(40)
    ->lon(-70)
    ->validationMethod('IGNORE_MALFORMED');

$searchResult = Store::searchQuery($query)->execute();