search-shards.asciidoc 4.7 KB

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