OpenSearch/docs/reference/mapping/params/geohash.asciidoc

79 lines
2.2 KiB
Plaintext

[[geohash]]
=== `geohash`
deprecated[5.0.0, Will be removed in the next major version.]
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, with this mapping:
[source,js]
--------------------------------------------------
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"location": {
"type": "geo_point", <1>
"geohash": true
}
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[warning:geo_point geohash parameter is deprecated and will be removed in the next major release]
You can index a document and use this query:
[source,js]
--------------------------------------------------
PUT my_index/my_type/1?refresh
{
"location": {
"lat": 41.12,
"lon": -71.34
}
}
GET my_index/_search?fielddata_fields=location.geohash <2>
{
"query": {
"prefix": {
"location.geohash": "drm3b" <3>
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[continued]
<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.
============================================