geo-shape-query.asciidoc 3.1 KB

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