geo-shape-query.asciidoc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. [[query-dsl-geo-shape-query]]
  2. == GeoShape Filter
  3. Filter documents indexed using the `geo_shape` type.
  4. Requires the <<mapping-geo-shape-type,geo_shape
  5. Mapping>>.
  6. The `geo_shape` query uses the same grid square representation as the
  7. geo_shape mapping to find documents that have a shape that intersects
  8. with the query shape. It will also use the same PrefixTree configuration
  9. as defined for the field mapping.
  10. [float]
  11. ==== Filter Format
  12. The Filter supports two ways of defining the Filter shape, either by
  13. providing a whole shape definition, or by referencing the name of a shape
  14. pre-indexed in another index. Both formats are defined below with
  15. examples.
  16. [float]
  17. ===== Provided Shape Definition
  18. Similar to the `geo_shape` type, the `geo_shape` Filter uses
  19. http://www.geojson.org[GeoJSON] to represent shapes.
  20. Given a document that looks like this:
  21. [source,js]
  22. --------------------------------------------------
  23. {
  24. "name": "Wind & Wetter, Berlin, Germany",
  25. "location": {
  26. "type": "Point",
  27. "coordinates": [13.400544, 52.530286]
  28. }
  29. }
  30. --------------------------------------------------
  31. The following query will find the point using the Elasticsearch's
  32. `envelope` GeoJSON extension:
  33. [source,js]
  34. --------------------------------------------------
  35. {
  36. "query":{
  37. "filtered": {
  38. "query": {
  39. "match_all": {}
  40. },
  41. "filter": {
  42. "geo_shape": {
  43. "location": {
  44. "shape": {
  45. "type": "envelope",
  46. "coordinates" : [[13.0, 53.0], [14.0, 52.0]]
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. --------------------------------------------------
  55. [float]
  56. ===== Pre-Indexed Shape
  57. The Filter also supports using a shape which has already been indexed in
  58. another index and/or index type. This is particularly useful for when
  59. you have a pre-defined list of shapes which are useful to your
  60. application and you want to reference this using a logical name (for
  61. example 'New Zealand') rather than having to provide their coordinates
  62. each time. In this situation it is only necessary to provide:
  63. * `id` - The ID of the document that containing the pre-indexed shape.
  64. * `index` - Name of the index where the pre-indexed shape is. Defaults
  65. to 'shapes'.
  66. * `type` - Index type where the pre-indexed shape is.
  67. * `path` - The field specified as path containing the pre-indexed shape.
  68. Defaults to 'shape'.
  69. The following is an example of using the Filter with a pre-indexed
  70. shape:
  71. [source,js]
  72. --------------------------------------------------
  73. {
  74. "filtered": {
  75. "query": {
  76. "match_all": {}
  77. },
  78. "filter": {
  79. "geo_shape": {
  80. "location": {
  81. "indexed_shape": {
  82. "id": "DEU",
  83. "type": "countries",
  84. "index": "shapes",
  85. "path": "location"
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. --------------------------------------------------