geo-polygon-query.asciidoc 3.7 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. "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 in `[lon, lat]`, note, the order of lon/lat here in order to
  45. conform with http://geojson.org/[GeoJSON].
  46. [source,js]
  47. --------------------------------------------------
  48. GET /_search
  49. {
  50. "query": {
  51. "bool" : {
  52. "must" : {
  53. "match_all" : {}
  54. },
  55. "filter" : {
  56. "geo_polygon" : {
  57. "person.location" : {
  58. "points" : [
  59. [-70, 40],
  60. [-80, 30],
  61. [-90, 20]
  62. ]
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. // CONSOLE
  71. [float]
  72. ===== Lat Lon as String
  73. Format in `lat,lon`.
  74. [source,js]
  75. --------------------------------------------------
  76. GET /_search
  77. {
  78. "query": {
  79. "bool" : {
  80. "must" : {
  81. "match_all" : {}
  82. },
  83. "filter" : {
  84. "geo_polygon" : {
  85. "person.location" : {
  86. "points" : [
  87. "40, -70",
  88. "30, -80",
  89. "20, -90"
  90. ]
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. --------------------------------------------------
  98. // CONSOLE
  99. [float]
  100. ===== Geohash
  101. [source,js]
  102. --------------------------------------------------
  103. GET /_search
  104. {
  105. "query": {
  106. "bool" : {
  107. "must" : {
  108. "match_all" : {}
  109. },
  110. "filter" : {
  111. "geo_polygon" : {
  112. "person.location" : {
  113. "points" : [
  114. "drn5x1g8cu2y",
  115. "30, -80",
  116. "20, -90"
  117. ]
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. --------------------------------------------------
  125. // CONSOLE
  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.