geohash-precision.asciidoc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. [[geohash-precision]]
  2. === `geohash_precision`
  3. Geohashes are a form of lat/lon encoding which divides the earth up into
  4. a grid. Each cell in this grid is represented by a geohash string. Each
  5. cell in turn can be further subdivided into smaller cells which are
  6. represented by a longer string. So the longer the geohash, the smaller
  7. (and thus more accurate) the cell is.
  8. The `geohash_precision` setting controls the length of the geohash that is
  9. indexed when the <<geohash,`geohash`>> option is enabled, and the maximum
  10. geohash length when the <<geohash-prefix,`geohash_prefix`>> option is enabled.
  11. It accepts:
  12. * a number between 1 and 12 (default), which represents the length of the geohash.
  13. * a <<distance-units,distance>>, e.g. `1km`.
  14. If a distance is specified, it will be translated to the smallest
  15. geohash-length that will provide the requested resolution.
  16. For example:
  17. [source,js]
  18. --------------------------------------------------
  19. PUT my_index
  20. {
  21. "mappings": {
  22. "my_type": {
  23. "properties": {
  24. "location": {
  25. "type": "geo_point",
  26. "geohash_prefix": true,
  27. "geohash_precision": 6 <1>
  28. }
  29. }
  30. }
  31. }
  32. }
  33. PUT my_index/my_type/1
  34. {
  35. "location": {
  36. "lat": 41.12,
  37. "lon": -71.34
  38. }
  39. }
  40. GET my_index/_search?fielddata_fields=location.geohash
  41. {
  42. "query": {
  43. "term": {
  44. "location.geohash": "drm3bt"
  45. }
  46. }
  47. }
  48. --------------------------------------------------
  49. // AUTOSENSE
  50. <1> A `geohash_precision` of 6 equates to geohash cells of approximately 1.26km x 0.6km