search-shards.asciidoc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. [[search-shards]]
  2. === Search shards API
  3. ++++
  4. <titleabbrev>Search shards</titleabbrev>
  5. ++++
  6. Returns the indices and shards that a search request would be executed against.
  7. [source,console]
  8. --------------------------------------------------
  9. GET /my-index-000001/_search_shards
  10. --------------------------------------------------
  11. // TEST[s/^/PUT my-index-000001\n{"settings":{"index.number_of_shards":5}}\n/]
  12. [[search-shards-api-request]]
  13. ==== {api-request-title}
  14. `GET /<target>/_search_shards`
  15. [[search-shards-api-prereqs]]
  16. ==== {api-prereq-title}
  17. * If the {es} {security-features} are enabled, you must have the
  18. `view_index_metadata` or `manage` <<privileges-list-indices,index privilege>>
  19. for the target data stream, index, or alias.
  20. [[search-shards-api-desc]]
  21. ==== {api-description-title}
  22. The search shards api returns the indices and shards that a search request would
  23. be executed against. This can give useful feedback for working out issues or
  24. planning optimizations with routing and shard preferences. When filtered aliases
  25. are used, the filter is returned as part of the `indices` section.
  26. [[search-shards-api-path-params]]
  27. ==== {api-path-parms-title}
  28. `<target>`::
  29. (Optional, string) Comma-separated list of data streams, indices, and aliases to
  30. search. Supports wildcards (`*`). To search all data streams and indices, omit
  31. this parameter or use `*` or `_all`.
  32. [[search-shards-api-query-params]]
  33. ==== {api-query-parms-title}
  34. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  35. +
  36. Defaults to `true`.
  37. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  38. +
  39. --
  40. Defaults to `open`.
  41. --
  42. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  43. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=local]
  44. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=preference]
  45. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=routing]
  46. [[search-shards-api-example]]
  47. ==== {api-examples-title}
  48. [source,console]
  49. --------------------------------------------------
  50. GET /my-index-000001/_search_shards
  51. --------------------------------------------------
  52. // TEST[s/^/PUT my-index-000001\n{"settings":{"index.number_of_shards":5}}\n/]
  53. The API returns the following result:
  54. [source,console-result]
  55. --------------------------------------------------
  56. {
  57. "nodes": ...,
  58. "indices" : {
  59. "my-index-000001": { }
  60. },
  61. "shards": [
  62. [
  63. {
  64. "index": "my-index-000001",
  65. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  66. "primary": true,
  67. "shard": 0,
  68. "state": "STARTED",
  69. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  70. "relocating_node": null
  71. }
  72. ],
  73. [
  74. {
  75. "index": "my-index-000001",
  76. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  77. "primary": true,
  78. "shard": 1,
  79. "state": "STARTED",
  80. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  81. "relocating_node": null
  82. }
  83. ],
  84. [
  85. {
  86. "index": "my-index-000001",
  87. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  88. "primary": true,
  89. "shard": 2,
  90. "state": "STARTED",
  91. "allocation_id": {"id":"Nwl0wbMBTHCWjEEbGYGapg"},
  92. "relocating_node": null
  93. }
  94. ],
  95. [
  96. {
  97. "index": "my-index-000001",
  98. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  99. "primary": true,
  100. "shard": 3,
  101. "state": "STARTED",
  102. "allocation_id": {"id":"bU_KLGJISbW0RejwnwDPKw"},
  103. "relocating_node": null
  104. }
  105. ],
  106. [
  107. {
  108. "index": "my-index-000001",
  109. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  110. "primary": true,
  111. "shard": 4,
  112. "state": "STARTED",
  113. "allocation_id": {"id":"DMs7_giNSwmdqVukF7UydA"},
  114. "relocating_node": null
  115. }
  116. ]
  117. ]
  118. }
  119. --------------------------------------------------
  120. // TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
  121. // TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.0.0.node/]
  122. // TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.0.0.allocation_id.id/]
  123. // TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.1.0.allocation_id.id/]
  124. // TESTRESPONSE[s/Nwl0wbMBTHCWjEEbGYGapg/$body.shards.2.0.allocation_id.id/]
  125. // TESTRESPONSE[s/bU_KLGJISbW0RejwnwDPKw/$body.shards.3.0.allocation_id.id/]
  126. // TESTRESPONSE[s/DMs7_giNSwmdqVukF7UydA/$body.shards.4.0.allocation_id.id/]
  127. Specifying the same request, this time with a routing value:
  128. [source,console]
  129. --------------------------------------------------
  130. GET /my-index-000001/_search_shards?routing=foo,bar
  131. --------------------------------------------------
  132. // TEST[s/^/PUT my-index-000001\n{"settings":{"index.number_of_shards":5}}\n/]
  133. The API returns the following result:
  134. [source,console-result]
  135. --------------------------------------------------
  136. {
  137. "nodes": ...,
  138. "indices" : {
  139. "my-index-000001": { }
  140. },
  141. "shards": [
  142. [
  143. {
  144. "index": "my-index-000001",
  145. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  146. "primary": true,
  147. "shard": 2,
  148. "state": "STARTED",
  149. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  150. "relocating_node": null
  151. }
  152. ],
  153. [
  154. {
  155. "index": "my-index-000001",
  156. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  157. "primary": true,
  158. "shard": 3,
  159. "state": "STARTED",
  160. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  161. "relocating_node": null
  162. }
  163. ]
  164. ]
  165. }
  166. --------------------------------------------------
  167. // TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
  168. // TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.1.0.node/]
  169. // TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.1.0.allocation_id.id/]
  170. // TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.0.0.allocation_id.id/]
  171. Because of the specified routing values,
  172. the search is only executed against two of the shards.