geo-polygon-query.asciidoc 3.7 KB

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