geohash.asciidoc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. [[geohash]]
  2. === `geohash`
  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. Because geohashes are just strings, they can be stored in an inverted
  9. index like any other string, which makes querying them very efficient.
  10. If you enable the `geohash` option, a `geohash` ``sub-field'' will be indexed
  11. as, eg `.geohash`. The length of the geohash is controlled by the
  12. <<geohash-precision,`geohash_precision`>> parameter.
  13. If the <<geohash-prefix,`geohash_prefix`>> option is enabled, the `geohash`
  14. option will be enabled automatically.
  15. For example:
  16. [source,js]
  17. --------------------------------------------------
  18. PUT my_index
  19. {
  20. "mappings": {
  21. "my_type": {
  22. "properties": {
  23. "location": {
  24. "type": "geo_point", <1>
  25. "geohash": true
  26. }
  27. }
  28. }
  29. }
  30. }
  31. PUT my_index/my_type/1
  32. {
  33. "location": {
  34. "lat": 41.12,
  35. "lon": -71.34
  36. }
  37. }
  38. GET my_index/_search?fielddata_fields=location.geohash <2>
  39. {
  40. "query": {
  41. "prefix": {
  42. "location.geohash": "drm3b" <3>
  43. }
  44. }
  45. }
  46. --------------------------------------------------
  47. // AUTOSENSE
  48. <1> A `location.geohash` field will be indexed for each geo-point.
  49. <2> The geohash can be retrieved with <<doc-values,`doc_values`>>.
  50. <3> A <<query-dsl-prefix-query,`prefix`>> query can find all geohashes which start with a particular prefix.
  51. [WARNING]
  52. ============================================
  53. A `prefix` query on geohashes is expensive. Instead, consider using the
  54. <<geohash-prefix,`geohash_prefix`>> to pay the expense once at index time
  55. instead of on every query.
  56. ============================================