geo-polygon-query.asciidoc 2.5 KB

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