Geo-point field type

Fields of type geo_point accept latitude-longitude pairs, which can be used:

There are five ways that a geo-point may be specified, as demonstrated below:

  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "location": {
  6. "type": "geo_point"
  7. }
  8. }
  9. }
  10. }
  11. PUT my-index-000001/_doc/1
  12. {
  13. "text": "Geo-point as an object",
  14. "location": {
  15. "lat": 41.12,
  16. "lon": -71.34
  17. }
  18. }
  19. PUT my-index-000001/_doc/2
  20. {
  21. "text": "Geo-point as a string",
  22. "location": "41.12,-71.34"
  23. }
  24. PUT my-index-000001/_doc/3
  25. {
  26. "text": "Geo-point as a geohash",
  27. "location": "drm3btev3e86"
  28. }
  29. PUT my-index-000001/_doc/4
  30. {
  31. "text": "Geo-point as an array",
  32. "location": [ -71.34, 41.12 ]
  33. }
  34. PUT my-index-000001/_doc/5
  35. {
  36. "text": "Geo-point as a WKT POINT primitive",
  37. "location" : "POINT (-71.34 41.12)"
  38. }
  39. GET my-index-000001/_search
  40. {
  41. "query": {
  42. "geo_bounding_box": {
  43. "location": {
  44. "top_left": {
  45. "lat": 42,
  46. "lon": -72
  47. },
  48. "bottom_right": {
  49. "lat": 40,
  50. "lon": -74
  51. }
  52. }
  53. }
  54. }
  55. }

Geo-point expressed as an object, with lat and lon keys.

Geo-point expressed as a string with the format: “lat,lon”.

Geo-point expressed as a geohash.

Geo-point expressed as an array with the format: [ lon, lat]

Geo-point expressed as a Well-Known Text POINT with the format: “POINT(lon lat)”

A geo-bounding box query which finds all geo-points that fall inside the box.

Geo-points expressed as an array or string

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.

Parameters for geo_point fields

The following parameters are accepted by geo_point fields:

ignore_malformed

If true, malformed geo-points are ignored. If false (default), malformed geo-points throw an exception and reject the whole document.

ignore_z_value

If true (default) three dimension points will be accepted (stored in source) but only latitude and longitude values will be indexed; the third dimension is ignored. If false, geo-points containing any more than latitude and longitude (two dimensions) values throw an exception and reject the whole document.

null_value

Accepts an geopoint value which is substituted for any explicit null values. Defaults to null, which means the field is treated as missing.

Using geo-points in scripts

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:

  1. def geopoint = doc['location'].value;
  2. def lat = geopoint.lat;
  3. def lon = geopoint.lon;

For performance reasons, it is better to access the lat/lon values directly:

  1. def lat = doc['location'].lat;
  2. def lon = doc['location'].lon;