search-shards.asciidoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. [[search-shards]]
  2. == Search Shards API
  3. The search shards api returns the indices and shards that a search request would
  4. be executed against. This can give useful feedback for working out issues or
  5. planning optimizations with routing and shard preferences.
  6. The `index` and `type` parameters may be single values, or comma-separated.
  7. [float]
  8. === Usage
  9. Full example:
  10. [source,js]
  11. --------------------------------------------------
  12. GET /twitter/_search_shards
  13. --------------------------------------------------
  14. // CONSOLE
  15. // TEST[s/^/PUT twitter\n/]
  16. This will yield the following result:
  17. [source,js]
  18. --------------------------------------------------
  19. {
  20. "nodes": ...,
  21. "shards": [
  22. [
  23. {
  24. "index": "twitter",
  25. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  26. "primary": true,
  27. "shard": 0,
  28. "state": "STARTED",
  29. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  30. "relocating_node": null
  31. }
  32. ],
  33. [
  34. {
  35. "index": "twitter",
  36. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  37. "primary": true,
  38. "shard": 1,
  39. "state": "STARTED",
  40. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  41. "relocating_node": null
  42. }
  43. ],
  44. [
  45. {
  46. "index": "twitter",
  47. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  48. "primary": true,
  49. "shard": 2,
  50. "state": "STARTED",
  51. "allocation_id": {"id":"Nwl0wbMBTHCWjEEbGYGapg"},
  52. "relocating_node": null
  53. }
  54. ],
  55. [
  56. {
  57. "index": "twitter",
  58. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  59. "primary": true,
  60. "shard": 3,
  61. "state": "STARTED",
  62. "allocation_id": {"id":"bU_KLGJISbW0RejwnwDPKw"},
  63. "relocating_node": null
  64. }
  65. ],
  66. [
  67. {
  68. "index": "twitter",
  69. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  70. "primary": true,
  71. "shard": 4,
  72. "state": "STARTED",
  73. "allocation_id": {"id":"DMs7_giNSwmdqVukF7UydA"},
  74. "relocating_node": null
  75. }
  76. ]
  77. ]
  78. }
  79. --------------------------------------------------
  80. // TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
  81. // TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.0.0.node/]
  82. // TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.0.0.allocation_id.id/]
  83. // TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.1.0.allocation_id.id/]
  84. // TESTRESPONSE[s/Nwl0wbMBTHCWjEEbGYGapg/$body.shards.2.0.allocation_id.id/]
  85. // TESTRESPONSE[s/bU_KLGJISbW0RejwnwDPKw/$body.shards.3.0.allocation_id.id/]
  86. // TESTRESPONSE[s/DMs7_giNSwmdqVukF7UydA/$body.shards.4.0.allocation_id.id/]
  87. And specifying the same request, this time with a routing value:
  88. [source,js]
  89. --------------------------------------------------
  90. GET /twitter/_search_shards?routing=foo,baz
  91. --------------------------------------------------
  92. // CONSOLE
  93. // TEST[s/^/PUT twitter\n/]
  94. This will yield the following result:
  95. [source,js]
  96. --------------------------------------------------
  97. {
  98. "nodes": ...,
  99. "shards": [
  100. [
  101. {
  102. "index": "twitter",
  103. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  104. "primary": true,
  105. "shard": 0,
  106. "state": "STARTED",
  107. "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
  108. "relocating_node": null
  109. }
  110. ],
  111. [
  112. {
  113. "index": "twitter",
  114. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  115. "primary": true,
  116. "shard": 1,
  117. "state": "STARTED",
  118. "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
  119. "relocating_node": null
  120. }
  121. ]
  122. ]
  123. }
  124. --------------------------------------------------
  125. // TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/]
  126. // TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.0.0.node/]
  127. // TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.0.0.allocation_id.id/]
  128. // TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.1.0.allocation_id.id/]
  129. This time the search will only be executed against two of the shards, because
  130. routing values have been specified.
  131. [float]
  132. === All parameters:
  133. [horizontal]
  134. `routing`::
  135. A comma-separated list of routing values to take into account when
  136. determining which shards a request would be executed against.
  137. `preference`::
  138. Controls a `preference` of which shard replicas to execute the search
  139. request on. By default, the operation is randomized between the shard
  140. replicas. See the link:search-request-preference.html[preference]
  141. documentation for a list of all acceptable values.
  142. `local`::
  143. A boolean value whether to read the cluster state locally in order to
  144. determine where shards are allocated instead of using the Master node's
  145. cluster state.