65 lines
1.6 KiB
Plaintext
65 lines
1.6 KiB
Plaintext
[[geohash-prefix]]
|
|
=== `geohash_prefix`
|
|
|
|
Geohashes are a form of lat/lon encoding which divides the earth up into
|
|
a grid. Each cell in this grid is represented by a geohash string. Each
|
|
cell in turn can be further subdivided into smaller cells which are
|
|
represented by a longer string. So the longer the geohash, the smaller
|
|
(and thus more accurate) the cell is.
|
|
|
|
While the <<geohash,`geohash`>> option enables indexing the geohash that
|
|
corresponds to the lat/lon point, at the specified
|
|
<<geohash-precision,precision>>, the `geohash_prefix` option will also
|
|
index all the enclosing cells as well.
|
|
|
|
For instance, a geohash of `drm3btev3e86` will index all of the following
|
|
terms: [ `d`, `dr`, `drm`, `drm3`, `drm3b`, `drm3bt`, `drm3bte`, `drm3btev`,
|
|
`drm3btev3`, `drm3btev3e`, `drm3btev3e8`, `drm3btev3e86` ].
|
|
|
|
The geohash prefixes can be used with the
|
|
<<query-dsl-geohash-cell-query,`geohash_cell` query>> to find points within a
|
|
particular geohash, or its neighbours:
|
|
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT my_index
|
|
{
|
|
"mappings": {
|
|
"my_type": {
|
|
"properties": {
|
|
"location": {
|
|
"type": "geo_point",
|
|
"geohash_prefix": true,
|
|
"geohash_precision": 6
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
PUT my_index/my_type/1
|
|
{
|
|
"location": {
|
|
"lat": 41.12,
|
|
"lon": -71.34
|
|
}
|
|
}
|
|
|
|
GET my_index/_search?fielddata_fields=location.geohash
|
|
{
|
|
"query": {
|
|
"geohash_cell": {
|
|
"location": {
|
|
"lat": 41.02,
|
|
"lon": -71.48
|
|
},
|
|
"precision": 4, <1>
|
|
"neighbors": true <1>
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// AUTOSENSE
|
|
|