Fields of type geo_point
accept latitude-longitude pairs, which can be used:
There are four ways that a geo-point may be specified, as demonstrated below:
PUT my_index { "mappings": { "properties": { "location": { "type": "geo_point" } } } } PUT my_index/_doc/1 { "text": "Geo-point as an object", "location": { "lat": 41.12, "lon": -71.34 } } PUT my_index/_doc/2 { "text": "Geo-point as a string", "location": "41.12,-71.34" } PUT my_index/_doc/3 { "text": "Geo-point as a geohash", "location": "drm3btev3e86" } PUT my_index/_doc/4 { "text": "Geo-point as an array", "location": [ -71.34, 41.12 ] } GET my_index/_search { "query": { "geo_bounding_box": { "location": { "top_left": { "lat": 42, "lon": -72 }, "bottom_right": { "lat": 40, "lon": -74 } } } } }
Geo-point expressed as an object, with | |
Geo-point expressed as a string with the format: | |
Geo-point expressed as a geohash. | |
Geo-point expressed as an array with the format: [ | |
A geo-bounding box query which finds all geo-points that fall inside the box. |
Please note that string geo-points are ordered as lat,lon
, while array
geo-points are ordered as the reverse: lon,lat
.
Originally, lat,lon
was used for both array and string, but the array
format was changed early on to conform to the format used by GeoJSON.
A point can be expressed as a geohash. Geohashes are base32 encoded strings of the bits of the latitude and longitude interleaved. Each character in a geohash adds additional 5 bits to the precision. So the longer the hash, the more precise it is. For the indexing purposed geohashs are translated into latitude-longitude pairs. During this process only first 12 characters are used, so specifying more than 12 characters in a geohash doesn’t increase the precision. The 12 characters provide 60 bits, which should reduce a possible error to less than 2cm.
The following parameters are accepted by geo_point
fields:
If | |
|
If |
Accepts an geopoint value which is substituted for any explicit |
When accessing the value of a geo-point in a script, the value is returned as
a GeoPoint
object, which allows access to the .lat
and .lon
values
respectively:
def geopoint = doc['location'].value; def lat = geopoint.lat; def lon = geopoint.lon;
For performance reasons, it is better to access the lat/lon values directly:
def lat = doc['location'].lat; def lon = doc['location'].lon;