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
defines how to compute the distance:
$query = Query::geoDistance()
->field('location')
->distance('200km')
->lat(40)
->lon(-70)
->distanceType('plane');
$searchResult = Store::searchQuery($query)->execute();
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();
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();
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
defines the geo point latitude:
$query = Query::geoDistance()
->field('location')
->distance('200km')
->lat(40)
->lon(-70);
$searchResult = Store::searchQuery($query)->execute();
lon
defines the geo point longitude:
$query = Query::geoDistance()
->field('location')
->distance('200km')
->lat(40)
->lon(-70);
$searchResult = Store::searchQuery($query)->execute();
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();
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:
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
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();
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();
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();