Geospatial Searches
Geospatial allow searching within arbitrary “geo-shapes” such as rectangles, polygons, circles, points etc.
for querying geospatial searches, you can use any of the supported shapes:
Exact Matching
Use _point
to directly match an specific exact point:
SEARCH /bank/
{
"_query": {
"checkin": {
"_point": {
"_latitude": 41.50343,
"_longitude": -74.01042
}
}
}
}
Match Within
Although you certainly can use any of the geospatial shapes in the same way we
used Point for Exact Matching, to directly match an specific
exact shape, you will probably more likely need to find documents within the
given shape. For that, the _in
keyword is needed:
SEARCH /bank/
{
"_query": {
"checkin": {
"_in": {
"_circle": {
"_latitude": 41.50830,
"_longitude": -73.97696,
"_radius": 5000
}
}
}
}
}
In the example above we are searching inside a circle with it’s center is given
by _latitude
, _longitude
and a _radius
(see Supported Distance Units).
Caution
For searching inside the given shape you must use _in
keyword.
Otherwise you’d be searching for the shape itself, not what’s in it.