search-shards.asciidoc 5.3 KB

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