Skip to content

Latest commit

 

History

History
202 lines (145 loc) · 5.41 KB

geo-queries.md

File metadata and controls

202 lines (145 loc) · 5.41 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();

Geo-Shape

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

$query = Query::geoShape()
    ->field('location')
    ->shape('envelope', [[13.0, 53.0], [14.0, 52.0]])
    ->relation('within');

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

Available methods:

field

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

$query = Query::geoShape()
    ->field('location')
    ->shape('envelope', [[13.0, 53.0], [14.0, 52.0]])
    ->relation('within');

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

relation

relation defines a spatial relation when searching a geo field:

$query = Query::geoShape()
    ->field('location')
    ->shape('envelope', [[13.0, 53.0], [14.0, 52.0]])
    ->relation('within');

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

shape

Use shape to define a GeoJSON representation of a shape:

$query = Query::geoShape()
    ->field('location')
    ->shape('envelope', [[13.0, 53.0], [14.0, 52.0]])
    ->relation('within');

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

ignoreUnmapped

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

$query = Query::geoShape()
    ->field('location')
    ->shape('envelope', [[13.0, 53.0], [14.0, 52.0]])
    ->relation('within')
    ->ignoreUnmapped(true);

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