geo-polygon-query.asciidoc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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,console]
  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. [float]
  33. ==== Query Options
  34. [cols="<,<",options="header",]
  35. |=======================================================================
  36. |Option |Description
  37. |`_name` |Optional name field to identify the filter
  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 as `[lon, lat]`
  47. Note: the order of lon/lat here must
  48. conform with http://geojson.org/[GeoJSON].
  49. [source,console]
  50. --------------------------------------------------
  51. GET /_search
  52. {
  53. "query": {
  54. "bool" : {
  55. "must" : {
  56. "match_all" : {}
  57. },
  58. "filter" : {
  59. "geo_polygon" : {
  60. "person.location" : {
  61. "points" : [
  62. [-70, 40],
  63. [-80, 30],
  64. [-90, 20]
  65. ]
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. --------------------------------------------------
  73. [float]
  74. ===== Lat Lon as String
  75. Format in `lat,lon`.
  76. [source,console]
  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. [float]
  101. ===== Geohash
  102. [source,console]
  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. [float]
  127. ==== geo_point Type
  128. The query *requires* the <<geo-point,`geo_point`>> type to be set on the
  129. relevant field.
  130. [float]
  131. ==== Ignore Unmapped
  132. When set to `true` the `ignore_unmapped` option will ignore an unmapped field
  133. and will not match any documents for this query. This can be useful when
  134. querying multiple indexes which might have different mappings. When set to
  135. `false` (the default value) the query will throw an exception if the field
  136. is not mapped.