geo-polygon-query.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. GET /_search
  8. {
  9. "query": {
  10. "bool" : {
  11. "query" : {
  12. "geo_polygon" : {
  13. "person.location" : {
  14. "points" : [
  15. {"lat" : 40, "lon" : -70},
  16. {"lat" : 30, "lon" : -80},
  17. {"lat" : 20, "lon" : -90}
  18. ]
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }
  25. --------------------------------------------------
  26. // CONSOLE
  27. [float]
  28. ==== Query Options
  29. [cols="<,<",options="header",]
  30. |=======================================================================
  31. |Option |Description
  32. |`_name` |Optional name field to identify the filter
  33. |`ignore_malformed` |deprecated[5.0.0,Use `validation_method` instead] Set to `true` to accept geo points with invalid latitude or
  34. longitude (default is `false`).
  35. |`validation_method` |Set to `IGNORE_MALFORMED` to accept geo points with
  36. invalid latitude or longitude, `COERCE` to try and infer correct latitude
  37. or longitude, or `STRICT` (default is `STRICT`).
  38. |=======================================================================
  39. [float]
  40. ==== Allowed Formats
  41. [float]
  42. ===== Lat Long as Array
  43. Format in `[lon, lat]`, note, the order of lon/lat here in order to
  44. conform with http://geojson.org/[GeoJSON].
  45. [source,js]
  46. --------------------------------------------------
  47. GET /_search
  48. {
  49. "query": {
  50. "bool" : {
  51. "must" : {
  52. "match_all" : {}
  53. },
  54. "filter" : {
  55. "geo_polygon" : {
  56. "person.location" : {
  57. "points" : [
  58. [-70, 40],
  59. [-80, 30],
  60. [-90, 20]
  61. ]
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. --------------------------------------------------
  69. // CONSOLE
  70. [float]
  71. ===== Lat Lon as String
  72. Format in `lat,lon`.
  73. [source,js]
  74. --------------------------------------------------
  75. GET /_search
  76. {
  77. "query": {
  78. "bool" : {
  79. "must" : {
  80. "match_all" : {}
  81. },
  82. "filter" : {
  83. "geo_polygon" : {
  84. "person.location" : {
  85. "points" : [
  86. "40, -70",
  87. "30, -80",
  88. "20, -90"
  89. ]
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. --------------------------------------------------
  97. // CONSOLE
  98. [float]
  99. ===== Geohash
  100. [source,js]
  101. --------------------------------------------------
  102. GET /_search
  103. {
  104. "query": {
  105. "bool" : {
  106. "must" : {
  107. "match_all" : {}
  108. },
  109. "filter" : {
  110. "geo_polygon" : {
  111. "person.location" : {
  112. "points" : [
  113. "drn5x1g8cu2y",
  114. "30, -80",
  115. "20, -90"
  116. ]
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. --------------------------------------------------
  124. // CONSOLE
  125. [float]
  126. ==== geo_point Type
  127. The query *requires* the <<geo-point,`geo_point`>> type to be set on the
  128. relevant field.
  129. [float]
  130. ==== Ignore Unmapped
  131. When set to `true` the `ignore_unmapped` option will ignore an unmapped field
  132. and will not match any documents for this query. This can be useful when
  133. querying multiple indexes which might have different mappings. When set to
  134. `false` (the default value) the query will throw an exception if the field
  135. is not mapped.