geohash-prefix.asciidoc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [[geohash-prefix]]
  2. === `geohash_prefix`
  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. While the <<geohash,`geohash`>> option enables indexing the geohash that
  9. corresponds to the lat/lon point, at the specified
  10. <<geohash-precision,precision>>, the `geohash_prefix` option will also
  11. index all the enclosing cells as well.
  12. For instance, a geohash of `drm3btev3e86` will index all of the following
  13. terms: [ `d`, `dr`, `drm`, `drm3`, `drm3b`, `drm3bt`, `drm3bte`, `drm3btev`,
  14. `drm3btev3`, `drm3btev3e`, `drm3btev3e8`, `drm3btev3e86` ].
  15. The geohash prefixes can be used with the
  16. <<query-dsl-geohash-cell-query,`geohash_cell` query>> to find points within a
  17. particular geohash, or its neighbours:
  18. [source,js]
  19. --------------------------------------------------
  20. PUT my_index
  21. {
  22. "mappings": {
  23. "my_type": {
  24. "properties": {
  25. "location": {
  26. "type": "geo_point",
  27. "geohash_prefix": true,
  28. "geohash_precision": 6
  29. }
  30. }
  31. }
  32. }
  33. }
  34. PUT my_index/my_type/1
  35. {
  36. "location": {
  37. "lat": 41.12,
  38. "lon": -71.34
  39. }
  40. }
  41. GET my_index/_search?fielddata_fields=location.geohash
  42. {
  43. "query": {
  44. "geohash_cell": {
  45. "location": {
  46. "lat": 41.02,
  47. "lon": -71.48
  48. },
  49. "precision": 4, <1>
  50. "neighbors": true <1>
  51. }
  52. }
  53. }
  54. --------------------------------------------------
  55. // AUTOSENSE