geohash_precision

edit

Geohashes 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.

The geohash_precision setting controls the length of the geohash that is indexed when the geohash option is enabled, and the maximum geohash length when the geohash_prefix option is enabled.

It accepts:

  • a number between 1 and 12 (default), which represents the length of the geohash.
  • a distance, e.g. 1km.

If a distance is specified, it will be translated to the smallest geohash-length that will provide the requested resolution.

For example:

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": {
    "term": {
      "location.geohash": "drm3bt"
    }
  }
}

A geohash_precision of 6 equates to geohash cells of approximately 1.26km x 0.6km