geohash-cell-query.asciidoc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. PUT /my_index
  14. {
  15. "mappings" : {
  16. "location": {
  17. "properties": {
  18. "pin": {
  19. "type": "geo_point",
  20. "geohash": true,
  21. "geohash_prefix": true,
  22. "geohash_precision": 10
  23. }
  24. }
  25. }
  26. }
  27. }
  28. --------------------------------------------------
  29. // CONSOLE
  30. // TESTSETUP
  31. The geohash cell can defined by all formats of `geo_points`. If such a cell is
  32. defined by a latitude and longitude pair the size of the cell needs to be
  33. setup. This can be done by the `precision` parameter of the filter. This
  34. parameter can be set to an integer value which sets the length of the geohash
  35. prefix. Instead of setting a geohash length directly it is also possible to
  36. define the precision as distance, in example `"precision": "50m"`. (See
  37. <<distance-units>>.)
  38. The `neighbor` option of the filter offers the possibility to filter cells
  39. next to the given cell.
  40. [source,js]
  41. --------------------------------------------------
  42. GET /_search
  43. {
  44. "query": {
  45. "bool" : {
  46. "must" : {
  47. "match_all" : {}
  48. },
  49. "filter" : {
  50. "geohash_cell": {
  51. "pin": {
  52. "lat": 13.4080,
  53. "lon": 52.5186
  54. },
  55. "precision": 3,
  56. "neighbors": true
  57. }
  58. }
  59. }
  60. }
  61. }
  62. --------------------------------------------------
  63. // CONSOLE
  64. [float]
  65. ==== Ignore Unmapped
  66. When set to `true` the `ignore_unmapped` option will ignore an unmapped field
  67. and will not match any documents for this query. This can be useful when
  68. querying multiple indexes which might have different mappings. When set to
  69. `false` (the default value) the query will throw an exception if the field
  70. is not mapped.