shape-query.asciidoc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. [[query-dsl-shape-query]]
  2. [role="xpack"]
  3. [testenv="basic"]
  4. === Shape query
  5. ++++
  6. <titleabbrev>Shape</titleabbrev>
  7. ++++
  8. Queries documents that contain fields indexed using the `shape` type.
  9. Requires the <<shape,`shape` Mapping>>.
  10. The query supports two ways of defining the target shape, either by
  11. providing a whole shape definition, or by referencing the name, or id, of a shape
  12. pre-indexed in another index. Both formats are defined below with
  13. examples.
  14. ==== Inline Shape Definition
  15. Similar to the `geo_shape` query, the `shape` query uses
  16. http://www.geojson.org[GeoJSON] or
  17. https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry[Well Known Text]
  18. (WKT) to represent shapes.
  19. Given the following index:
  20. [source,js]
  21. --------------------------------------------------
  22. PUT /example
  23. {
  24. "mappings": {
  25. "properties": {
  26. "geometry": {
  27. "type": "shape"
  28. }
  29. }
  30. }
  31. }
  32. POST /example/_doc?refresh
  33. {
  34. "name": "Lucky Landing",
  35. "location": {
  36. "type": "point",
  37. "coordinates": [1355.400544, 5255.530286]
  38. }
  39. }
  40. --------------------------------------------------
  41. // CONSOLE
  42. // TESTSETUP
  43. The following query will find the point using the Elasticsearch's
  44. `envelope` GeoJSON extension:
  45. [source,js]
  46. --------------------------------------------------
  47. GET /example/_search
  48. {
  49. "query":{
  50. "shape": {
  51. "geometry": {
  52. "shape": {
  53. "type": "envelope",
  54. "coordinates" : [[1355.0, 5355.0], [1400.0, 5200.0]]
  55. },
  56. "relation": "within"
  57. }
  58. }
  59. }
  60. }
  61. --------------------------------------------------
  62. // CONSOLE
  63. ==== Pre-Indexed Shape
  64. The Query also supports using a shape which has already been indexed in
  65. another index. This is particularly useful for when
  66. you have a pre-defined list of shapes which are useful to your
  67. application and you want to reference this using a logical name (for
  68. example 'New Zealand') rather than having to provide their coordinates
  69. each time. In this situation it is only necessary to provide:
  70. * `id` - The ID of the document that containing the pre-indexed shape.
  71. * `index` - Name of the index where the pre-indexed shape is. Defaults
  72. to 'shapes'.
  73. * `path` - The field specified as path containing the pre-indexed shape.
  74. Defaults to 'shape'.
  75. * `routing` - The routing of the shape document if required.
  76. The following is an example of using the Filter with a pre-indexed
  77. shape:
  78. [source,js]
  79. --------------------------------------------------
  80. PUT /shapes
  81. {
  82. "mappings": {
  83. "properties": {
  84. "geometry": {
  85. "type": "shape"
  86. }
  87. }
  88. }
  89. }
  90. PUT /shapes/_doc/footprint
  91. {
  92. "geometry": {
  93. "type": "envelope",
  94. "coordinates" : [[1355.0, 5355.0], [1400.0, 5200.0]]
  95. }
  96. }
  97. GET /example/_search
  98. {
  99. "query": {
  100. "shape": {
  101. "geometry": {
  102. "indexed_shape": {
  103. "index": "shapes",
  104. "id": "footprint",
  105. "path": "geometry"
  106. }
  107. }
  108. }
  109. }
  110. }
  111. --------------------------------------------------
  112. // CONSOLE
  113. ==== Spatial Relations
  114. The following is a complete list of spatial relation operators available:
  115. * `INTERSECTS` - (default) Return all documents whose `geo_shape` field
  116. intersects the query geometry.
  117. * `DISJOINT` - Return all documents whose `geo_shape` field
  118. has nothing in common with the query geometry.
  119. * `WITHIN` - Return all documents whose `geo_shape` field
  120. is within the query geometry.
  121. [float]
  122. ==== Ignore Unmapped
  123. When set to `true` the `ignore_unmapped` option will ignore an unmapped field
  124. and will not match any documents for this query. This can be useful when
  125. querying multiple indexes which might have different mappings. When set to
  126. `false` (the default value) the query will throw an exception if the field
  127. is not mapped.