geo-polygon-query.asciidoc 3.7 KB

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