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();