71 lines
1.8 KiB
Plaintext
71 lines
1.8 KiB
Plaintext
[[geohash]]
|
|
=== `geohash`
|
|
|
|
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.
|
|
|
|
Because geohashes are just strings, they can be stored in an inverted
|
|
index like any other string, which makes querying them very efficient.
|
|
|
|
If you enable the `geohash` option, a `geohash` ``sub-field'' will be indexed
|
|
as, eg `.geohash`. The length of the geohash is controlled by the
|
|
<<geohash-precision,`geohash_precision`>> parameter.
|
|
|
|
If the <<geohash-prefix,`geohash_prefix`>> option is enabled, the `geohash`
|
|
option will be enabled automatically.
|
|
|
|
For example:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT my_index
|
|
{
|
|
"mappings": {
|
|
"my_type": {
|
|
"properties": {
|
|
"location": {
|
|
"type": "geo_point", <1>
|
|
"geohash": true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
PUT my_index/my_type/1
|
|
{
|
|
"location": {
|
|
"lat": 41.12,
|
|
"lon": -71.34
|
|
}
|
|
}
|
|
|
|
GET my_index/_search?fielddata_fields=location.geohash <2>
|
|
{
|
|
"query": {
|
|
"prefix": {
|
|
"location.geohash": "drm3b" <3>
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
<1> A `location.geohash` field will be indexed for each geo-point.
|
|
<2> The geohash can be retrieved with <<doc-values,`doc_values`>>.
|
|
<3> A <<query-dsl-prefix-query,`prefix`>> query can find all geohashes which start with a particular prefix.
|
|
|
|
[WARNING]
|
|
============================================
|
|
|
|
A `prefix` query on geohashes is expensive. Instead, consider using the
|
|
<<geohash-prefix,`geohash_prefix`>> to pay the expense once at index time
|
|
instead of on every query.
|
|
|
|
============================================
|
|
|
|
|