geo-polygon-query.asciidoc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. [[query-dsl-geo-polygon-query]]
  2. === Geo Polygon Query
  3. A query allowing to include hits that only fall within a polygon of
  4. points. Here is an example:
  5. [source,js]
  6. --------------------------------------------------
  7. {
  8. "bool" : {
  9. "query" : {
  10. "match_all" : {}
  11. },
  12. "filter" : {
  13. "geo_polygon" : {
  14. "person.location" : {
  15. "points" : [
  16. {"lat" : 40, "lon" : -70},
  17. {"lat" : 30, "lon" : -80},
  18. {"lat" : 20, "lon" : -90}
  19. ]
  20. }
  21. }
  22. }
  23. }
  24. }
  25. --------------------------------------------------
  26. [float]
  27. ==== Query Options
  28. [cols="<,<",options="header",]
  29. |=======================================================================
  30. |Option |Description
  31. |`_name` |Optional name field to identify the filter
  32. |`coerce` |Set to `true` to normalize longitude and latitude values to a
  33. standard -180:180 / -90:90 coordinate system. (default is `false`).
  34. |`ignore_malformed` |Set to `true` to accept geo points with invalid latitude or
  35. longitude (default is `false`).
  36. |=======================================================================
  37. [float]
  38. ==== Allowed Formats
  39. [float]
  40. ===== Lat Long as Array
  41. Format in `[lon, lat]`, note, the order of lon/lat here in order to
  42. conform with http://geojson.org/[GeoJSON].
  43. [source,js]
  44. --------------------------------------------------
  45. {
  46. "bool" : {
  47. "must" : {
  48. "match_all" : {}
  49. },
  50. "filter" : {
  51. "geo_polygon" : {
  52. "person.location" : {
  53. "points" : [
  54. [-70, 40],
  55. [-80, 30],
  56. [-90, 20]
  57. ]
  58. }
  59. }
  60. }
  61. }
  62. }
  63. --------------------------------------------------
  64. [float]
  65. ===== Lat Lon as String
  66. Format in `lat,lon`.
  67. [source,js]
  68. --------------------------------------------------
  69. {
  70. "bool" : {
  71. "must" : {
  72. "match_all" : {}
  73. },
  74. "filter" : {
  75. "geo_polygon" : {
  76. "person.location" : {
  77. "points" : [
  78. "40, -70",
  79. "30, -80",
  80. "20, -90"
  81. ]
  82. }
  83. }
  84. }
  85. }
  86. }
  87. --------------------------------------------------
  88. [float]
  89. ===== Geohash
  90. [source,js]
  91. --------------------------------------------------
  92. {
  93. "bool" : {
  94. "must" : {
  95. "match_all" : {}
  96. },
  97. "filter" : {
  98. "geo_polygon" : {
  99. "person.location" : {
  100. "points" : [
  101. "drn5x1g8cu2y",
  102. "30, -80",
  103. "20, -90"
  104. ]
  105. }
  106. }
  107. }
  108. }
  109. }
  110. --------------------------------------------------
  111. [float]
  112. ==== geo_point Type
  113. The query *requires* the <<geo-point,`geo_point`>> type to be set on the
  114. relevant field.