WARNING: Version 2.3 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
geohash_prefix
editgeohash_prefix
editGeohashes are a form of lat/lon encoding which divides the earth up into a grid. Each cell in this grid is represented by a geohash string. Each cell in turn can be further subdivided into smaller cells which are represented by a longer string. So the longer the geohash, the smaller (and thus more accurate) the cell is.
While the geohash
option enables indexing the geohash that
corresponds to the lat/lon point, at the specified
precision, the geohash_prefix
option will also
index all the enclosing cells as well.
For instance, a geohash of drm3btev3e86
will index all of the following
terms: [ d
, dr
, drm
, drm3
, drm3b
, drm3bt
, drm3bte
, drm3btev
,
drm3btev3
, drm3btev3e
, drm3btev3e8
, drm3btev3e86
].
The geohash prefixes can be used with the
geohash_cell
query to find points within a
particular geohash, or its neighbours:
PUT my_index { "mappings": { "my_type": { "properties": { "location": { "type": "geo_point", "geohash_prefix": true, "geohash_precision": 6 } } } } } PUT my_index/my_type/1 { "location": { "lat": 41.12, "lon": -71.34 } } GET my_index/_search?fielddata_fields=location.geohash { "query": { "geohash_cell": { "location": { "lat": 41.02, "lon": -71.48 }, "precision": 4, "neighbors": true } } }