lat-lon.asciidoc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [[lat-lon]]
  2. === `lat_lon`
  3. <<geo-queries,Geo-queries>> are usually performed by plugging the value of
  4. each <<geo-point,`geo_point`>> field into a formula to determine whether it
  5. falls into the required area or not. Unlike most queries, the inverted index
  6. is not involved.
  7. Setting `lat_lon` to `true` causes the latitude and longitude values to be
  8. indexed as numeric fields (called `.lat` and `.lon`). These fields can be used
  9. by the <<query-dsl-geo-bounding-box-query,`geo_bounding_box`>> and
  10. <<query-dsl-geo-distance-query,`geo_distance`>> queries instead of
  11. performing in-memory calculations.
  12. [source,js]
  13. --------------------------------------------------
  14. PUT my_index
  15. {
  16. "mappings": {
  17. "my_type": {
  18. "properties": {
  19. "location": {
  20. "type": "geo_point",
  21. "lat_lon": true <1>
  22. }
  23. }
  24. }
  25. }
  26. }
  27. PUT my_index/my_type/1
  28. {
  29. "location": {
  30. "lat": 41.12,
  31. "lon": -71.34
  32. }
  33. }
  34. GET my_index/_search
  35. {
  36. "query": {
  37. "geo_distance": {
  38. "location": {
  39. "lat": 41,
  40. "lon": -71
  41. },
  42. "distance": "50km",
  43. "optimize_bbox": "indexed" <2>
  44. }
  45. }
  46. }
  47. --------------------------------------------------
  48. // AUTOSENSE
  49. <1> Setting `lat_lon` to true indexes the geo-point in the `location.lat` and `location.lon` fields.
  50. <2> The `indexed` option tells the geo-distance query to use the inverted index instead of the in-memory calculation.
  51. Whether the in-memory or indexed operation performs better depends both on
  52. your dataset and on the types of queries that you are running.
  53. NOTE: The `lat_lon` option only makes sense for single-value `geo_point`
  54. fields. It will not work with arrays of geo-points.