This filter translates the
lat/lon point into a geohash of the appropriate
length—in this example
dr5rsk—and looks for all locations that contain
that exact term.
However, the filter as written in the preceding example may not return all restaurants within 5km of the specified point. Remember that a geohash is just a rectangle, and the point may fall anywhere within that rectangle. If the point happens to fall near the edge of a geohash cell, the filter may well exclude any restaurants in the adjacent cell.
Clearly, looking for a geohash with precision
2km plus all the neighboring
cells results in quite a large search area. This filter is not built for
accuracy, but it is very efficient and can be used as a prefiltering step
before applying a more accurate geo-filter.
precision as a distance can be misleading. A
2km is converted to a geohash of length 6, which actually has dimensions
of about 1.2km x 0.6km. You may find it more understandable to specify an
actual length such as
The other advantage that this filter has over a
geo_bounding_box filter is
that it supports multiple locations per field.
lat_lon option that we
discussed in Optimizing Bounding Boxes is efficient, but only when there
is a single
lat/lon point per field.