2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-geohash-cell-query]]
|
2015-06-03 19:59:22 -04:00
|
|
|
=== Geohash Cell Query
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-05-05 02:27:52 -04:00
|
|
|
The `geohash_cell` query provides access to a hierarchy of geohashes.
|
2015-08-06 11:24:29 -04:00
|
|
|
By defining a geohash cell, only <<geo-point,geopoints>>
|
2013-11-08 07:50:40 -05:00
|
|
|
within this cell will match this filter.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
To get this filter work all prefixes of a geohash need to be indexed. In
|
|
|
|
example a geohash `u30` needs to be decomposed into three terms: `u30`,
|
|
|
|
`u3` and `u`. This decomposition must be enabled in the mapping of the
|
2015-08-06 11:24:29 -04:00
|
|
|
<<geo-point,geopoint>> field that's going to be filtered by
|
2013-11-08 07:50:40 -05:00
|
|
|
setting the `geohash_prefix` option:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
PUT /my_index
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
|
|
|
"mappings" : {
|
|
|
|
"location": {
|
|
|
|
"properties": {
|
|
|
|
"pin": {
|
|
|
|
"type": "geo_point",
|
|
|
|
"geohash": true,
|
2013-11-08 07:50:40 -05:00
|
|
|
"geohash_prefix": true,
|
|
|
|
"geohash_precision": 10
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
|
|
|
// TESTSETUP
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2013-11-08 07:50:40 -05:00
|
|
|
The geohash cell can defined by all formats of `geo_points`. If such a cell is
|
|
|
|
defined by a latitude and longitude pair the size of the cell needs to be
|
|
|
|
setup. This can be done by the `precision` parameter of the filter. This
|
|
|
|
parameter can be set to an integer value which sets the length of the geohash
|
|
|
|
prefix. Instead of setting a geohash length directly it is also possible to
|
|
|
|
define the precision as distance, in example `"precision": "50m"`. (See
|
|
|
|
<<distance-units>>.)
|
|
|
|
|
|
|
|
The `neighbor` option of the filter offers the possibility to filter cells
|
|
|
|
next to the given cell.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2016-05-24 05:58:43 -04:00
|
|
|
"query": {
|
|
|
|
"bool" : {
|
|
|
|
"must" : {
|
|
|
|
"match_all" : {}
|
|
|
|
},
|
|
|
|
"filter" : {
|
|
|
|
"geohash_cell": {
|
|
|
|
"pin": {
|
|
|
|
"lat": 13.4080,
|
|
|
|
"lon": 52.5186
|
|
|
|
},
|
|
|
|
"precision": 3,
|
|
|
|
"neighbors": true
|
|
|
|
}
|
2016-05-12 06:58:22 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
2014-06-12 06:09:52 -04:00
|
|
|
|
2016-04-14 06:38:48 -04:00
|
|
|
[float]
|
|
|
|
==== Ignore Unmapped
|
|
|
|
|
|
|
|
When set to `true` the `ignore_unmapped` option will ignore an unmapped field
|
|
|
|
and will not match any documents for this query. This can be useful when
|
|
|
|
querying multiple indexes which might have different mappings. When set to
|
|
|
|
`false` (the default value) the query will throw an exception if the field
|
|
|
|
is not mapped.
|