1
0

geo-polygon-query.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. [[query-dsl-geo-polygon-query]]
  2. === Geo-polygon query
  3. ++++
  4. <titleabbrev>Geo-polygon</titleabbrev>
  5. ++++
  6. deprecated::[7.12,Use <<query-dsl-geo-shape-query>> instead where polygons are defined in GeoJSON or http://docs.opengeospatial.org/is/18-010r7/18-010r7.html[Well-Known Text (WKT)].]
  7. A query returning hits that only fall within a polygon of
  8. points. Here is an example:
  9. [source,console]
  10. --------------------------------------------------
  11. GET /_search
  12. {
  13. "query": {
  14. "bool": {
  15. "must": {
  16. "match_all": {}
  17. },
  18. "filter": {
  19. "geo_polygon": {
  20. "person.location": {
  21. "points": [
  22. { "lat": 40, "lon": -70 },
  23. { "lat": 30, "lon": -80 },
  24. { "lat": 20, "lon": -90 }
  25. ]
  26. }
  27. }
  28. }
  29. }
  30. }
  31. }
  32. --------------------------------------------------
  33. // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]]
  34. [discrete]
  35. ==== Query Options
  36. [cols="<,<",options="header",]
  37. |=======================================================================
  38. |Option |Description
  39. |`_name` |Optional name field to identify the filter
  40. |`validation_method` |Set to `IGNORE_MALFORMED` to accept geo points with
  41. invalid latitude or longitude, `COERCE` to try and infer correct latitude
  42. or longitude, or `STRICT` (default is `STRICT`).
  43. |=======================================================================
  44. [discrete]
  45. ==== Allowed Formats
  46. [discrete]
  47. ===== Lat Long as Array
  48. Format as `[lon, lat]`
  49. Note: the order of lon/lat here must
  50. conform with http://geojson.org/[GeoJSON].
  51. [source,console]
  52. --------------------------------------------------
  53. GET /_search
  54. {
  55. "query": {
  56. "bool": {
  57. "must": {
  58. "match_all": {}
  59. },
  60. "filter": {
  61. "geo_polygon": {
  62. "person.location": {
  63. "points": [
  64. [ -70, 40 ],
  65. [ -80, 30 ],
  66. [ -90, 20 ]
  67. ]
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. --------------------------------------------------
  75. // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]]
  76. [discrete]
  77. ===== Lat Lon as String
  78. Format in `lat,lon`.
  79. [source,console]
  80. --------------------------------------------------
  81. GET /_search
  82. {
  83. "query": {
  84. "bool": {
  85. "must": {
  86. "match_all": {}
  87. },
  88. "filter": {
  89. "geo_polygon": {
  90. "person.location": {
  91. "points": [
  92. "40, -70",
  93. "30, -80",
  94. "20, -90"
  95. ]
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102. --------------------------------------------------
  103. // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]]
  104. [discrete]
  105. ===== Geohash
  106. [source,console]
  107. --------------------------------------------------
  108. GET /_search
  109. {
  110. "query": {
  111. "bool": {
  112. "must": {
  113. "match_all": {}
  114. },
  115. "filter": {
  116. "geo_polygon": {
  117. "person.location": {
  118. "points": [
  119. "drn5x1g8cu2y",
  120. "30, -80",
  121. "20, -90"
  122. ]
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. --------------------------------------------------
  130. // TEST[warning:Deprecated field [geo_polygon] used, replaced by [[geo_shape] query where polygons are defined in geojson or wkt]]
  131. [discrete]
  132. ==== `geo_point` type
  133. The query *requires* the <<geo-point,`geo_point`>> type to be set on the
  134. relevant field.
  135. [discrete]
  136. ==== Ignore Unmapped
  137. When set to `true` the `ignore_unmapped` option will ignore an unmapped field
  138. and will not match any documents for this query. This can be useful when
  139. querying multiple indexes which might have different mappings. When set to
  140. `false` (the default value) the query will throw an exception if the field
  141. is not mapped.