search-shards.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 /twitter/_search_shards
  7. --------------------------------------------------
  8. // TEST[s/^/PUT twitter\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::{docdir}/rest-api/common-parms.asciidoc[tag=index]
  21. [[search-shards-api-query-params]]
  22. ==== {api-query-parms-title}
  23. include::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  24. include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  25. +
  26. --
  27. Defaults to `open`.
  28. --
  29. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  30. include::{docdir}/rest-api/common-parms.asciidoc[tag=local]
  31. include::{docdir}/rest-api/common-parms.asciidoc[tag=preference]
  32. include::{docdir}/rest-api/common-parms.asciidoc[tag=routing]
  33. [[search-shards-api-example]]
  34. ==== {api-examples-title}
  35. [source,console]
  36. --------------------------------------------------
  37. GET /twitter/_search_shards
  38. --------------------------------------------------
  39. // TEST[s/^/PUT twitter\n{"settings":{"index.number_of_shards":5}}\n/]
  40. The API returns the following result:
  41. [source,console-result]
  42. --------------------------------------------------
  43. {
  44. "nodes": ...,
  45. "indices" : {
  46. "twitter": { }
  47. },
  48. "shards": [
  49. [
  50. {
  51. "index": "twitter",
  52. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  53. "primary": true,
  54. "shard": 0,
  55. "state": "STARTED",
  56. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  57. "relocating_node": null
  58. }
  59. ],
  60. [
  61. {
  62. "index": "twitter",
  63. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  64. "primary": true,
  65. "shard": 1,
  66. "state": "STARTED",
  67. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  68. "relocating_node": null
  69. }
  70. ],
  71. [
  72. {
  73. "index": "twitter",
  74. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  75. "primary": true,
  76. "shard": 2,
  77. "state": "STARTED",
  78. "allocation_id": {"id":"Nwl0wbMBTHCWjEEbGYGapg"},
  79. "relocating_node": null
  80. }
  81. ],
  82. [
  83. {
  84. "index": "twitter",
  85. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  86. "primary": true,
  87. "shard": 3,
  88. "state": "STARTED",
  89. "allocation_id": {"id":"bU_KLGJISbW0RejwnwDPKw"},
  90. "relocating_node": null
  91. }
  92. ],
  93. [
  94. {
  95. "index": "twitter",
  96. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  97. "primary": true,
  98. "shard": 4,
  99. "state": "STARTED",
  100. "allocation_id": {"id":"DMs7_giNSwmdqVukF7UydA"},
  101. "relocating_node": null
  102. }
  103. ]
  104. ]
  105. }
  106. --------------------------------------------------
  107. // TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
  108. // TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.0.0.node/]
  109. // TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.0.0.allocation_id.id/]
  110. // TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.1.0.allocation_id.id/]
  111. // TESTRESPONSE[s/Nwl0wbMBTHCWjEEbGYGapg/$body.shards.2.0.allocation_id.id/]
  112. // TESTRESPONSE[s/bU_KLGJISbW0RejwnwDPKw/$body.shards.3.0.allocation_id.id/]
  113. // TESTRESPONSE[s/DMs7_giNSwmdqVukF7UydA/$body.shards.4.0.allocation_id.id/]
  114. Specifying the same request, this time with a routing value:
  115. [source,console]
  116. --------------------------------------------------
  117. GET /twitter/_search_shards?routing=foo,bar
  118. --------------------------------------------------
  119. // TEST[s/^/PUT twitter\n{"settings":{"index.number_of_shards":5}}\n/]
  120. The API returns the following result:
  121. [source,console-result]
  122. --------------------------------------------------
  123. {
  124. "nodes": ...,
  125. "indices" : {
  126. "twitter": { }
  127. },
  128. "shards": [
  129. [
  130. {
  131. "index": "twitter",
  132. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  133. "primary": true,
  134. "shard": 2,
  135. "state": "STARTED",
  136. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  137. "relocating_node": null
  138. }
  139. ],
  140. [
  141. {
  142. "index": "twitter",
  143. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  144. "primary": true,
  145. "shard": 3,
  146. "state": "STARTED",
  147. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  148. "relocating_node": null
  149. }
  150. ]
  151. ]
  152. }
  153. --------------------------------------------------
  154. // TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
  155. // TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.1.0.node/]
  156. // TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.1.0.allocation_id.id/]
  157. // TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.0.0.allocation_id.id/]
  158. The search will only be executed against two of the shards, because outing
  159. values have been specified.