geo-polygon-query.asciidoc 3.4 KB

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