geohash-cell-query.asciidoc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [[query-dsl-geohash-cell-query]]
  2. === Geohash Cell Query
  3. The `geohash_cell` query provides access to a hierarchy of geohashes.
  4. By defining a geohash cell, only <<geo-point,geopoints>>
  5. within this cell will match this filter.
  6. To get this filter work all prefixes of a geohash need to be indexed. In
  7. example a geohash `u30` needs to be decomposed into three terms: `u30`,
  8. `u3` and `u`. This decomposition must be enabled in the mapping of the
  9. <<geo-point,geopoint>> field that's going to be filtered by
  10. setting the `geohash_prefix` option:
  11. [source,js]
  12. --------------------------------------------------
  13. {
  14. "mappings" : {
  15. "location": {
  16. "properties": {
  17. "pin": {
  18. "type": "geo_point",
  19. "geohash": true,
  20. "geohash_prefix": true,
  21. "geohash_precision": 10
  22. }
  23. }
  24. }
  25. }
  26. }
  27. --------------------------------------------------
  28. The geohash cell can defined by all formats of `geo_points`. If such a cell is
  29. defined by a latitude and longitude pair the size of the cell needs to be
  30. setup. This can be done by the `precision` parameter of the filter. This
  31. parameter can be set to an integer value which sets the length of the geohash
  32. prefix. Instead of setting a geohash length directly it is also possible to
  33. define the precision as distance, in example `"precision": "50m"`. (See
  34. <<distance-units>>.)
  35. The `neighbor` option of the filter offers the possibility to filter cells
  36. next to the given cell.
  37. [source,js]
  38. --------------------------------------------------
  39. {
  40. "bool" : {
  41. "must" : {
  42. "match_all" : {}
  43. },
  44. "filter" : {
  45. "geohash_cell": {
  46. "pin": {
  47. "lat": 13.4080,
  48. "lon": 52.5186
  49. },
  50. "precision": 3,
  51. "neighbors": true
  52. }
  53. }
  54. }
  55. }
  56. --------------------------------------------------