geo-polygon-query.asciidoc 2.9 KB

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