geo-polygon-query.asciidoc 3.8 KB

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