geo-polygon-query.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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` |Set to `true` to accept geo points with invalid latitude or
  33. longitude (default is `false`).
  34. |=======================================================================
  35. [float]
  36. ==== Allowed Formats
  37. [float]
  38. ===== Lat Long as Array
  39. Format in `[lon, lat]`, note, the order of lon/lat here in order to
  40. conform with http://geojson.org/[GeoJSON].
  41. [source,js]
  42. --------------------------------------------------
  43. {
  44. "bool" : {
  45. "must" : {
  46. "match_all" : {}
  47. },
  48. "filter" : {
  49. "geo_polygon" : {
  50. "person.location" : {
  51. "points" : [
  52. [-70, 40],
  53. [-80, 30],
  54. [-90, 20]
  55. ]
  56. }
  57. }
  58. }
  59. }
  60. }
  61. --------------------------------------------------
  62. [float]
  63. ===== Lat Lon as String
  64. Format in `lat,lon`.
  65. [source,js]
  66. --------------------------------------------------
  67. {
  68. "bool" : {
  69. "must" : {
  70. "match_all" : {}
  71. },
  72. "filter" : {
  73. "geo_polygon" : {
  74. "person.location" : {
  75. "points" : [
  76. "40, -70",
  77. "30, -80",
  78. "20, -90"
  79. ]
  80. }
  81. }
  82. }
  83. }
  84. }
  85. --------------------------------------------------
  86. [float]
  87. ===== Geohash
  88. [source,js]
  89. --------------------------------------------------
  90. {
  91. "bool" : {
  92. "must" : {
  93. "match_all" : {}
  94. },
  95. "filter" : {
  96. "geo_polygon" : {
  97. "person.location" : {
  98. "points" : [
  99. "drn5x1g8cu2y",
  100. "30, -80",
  101. "20, -90"
  102. ]
  103. }
  104. }
  105. }
  106. }
  107. }
  108. --------------------------------------------------
  109. [float]
  110. ==== geo_point Type
  111. The query *requires* the <<geo-point,`geo_point`>> type to be set on the
  112. relevant field.