search-shards.asciidoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. curl -XGET 'localhost:9200/twitter/_search_shards'
  13. --------------------------------------------------
  14. This will yield the following result:
  15. [source,js]
  16. --------------------------------------------------
  17. {
  18. "nodes": {
  19. "JklnKbD7Tyqi9TP3_Q_tBg": {
  20. "name": "Rl'nnd",
  21. "transport_address": "inet[/192.168.1.113:9300]"
  22. }
  23. },
  24. "shards": [
  25. [
  26. {
  27. "index": "twitter",
  28. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  29. "primary": true,
  30. "relocating_node": null,
  31. "shard": 3,
  32. "state": "STARTED"
  33. }
  34. ],
  35. [
  36. {
  37. "index": "twitter",
  38. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  39. "primary": true,
  40. "relocating_node": null,
  41. "shard": 4,
  42. "state": "STARTED"
  43. }
  44. ],
  45. [
  46. {
  47. "index": "twitter",
  48. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  49. "primary": true,
  50. "relocating_node": null,
  51. "shard": 0,
  52. "state": "STARTED"
  53. }
  54. ],
  55. [
  56. {
  57. "index": "twitter",
  58. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  59. "primary": true,
  60. "relocating_node": null,
  61. "shard": 2,
  62. "state": "STARTED"
  63. }
  64. ],
  65. [
  66. {
  67. "index": "twitter",
  68. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  69. "primary": true,
  70. "relocating_node": null,
  71. "shard": 1,
  72. "state": "STARTED"
  73. }
  74. ]
  75. ]
  76. }
  77. --------------------------------------------------
  78. And specifying the same request, this time with a routing value:
  79. [source,js]
  80. --------------------------------------------------
  81. curl -XGET 'localhost:9200/twitter/_search_shards?routing=foo,baz'
  82. --------------------------------------------------
  83. This will yield the following result:
  84. [source,js]
  85. --------------------------------------------------
  86. {
  87. "nodes": {
  88. "JklnKbD7Tyqi9TP3_Q_tBg": {
  89. "name": "Rl'nnd",
  90. "transport_address": "inet[/192.168.1.113:9300]"
  91. }
  92. },
  93. "shards": [
  94. [
  95. {
  96. "index": "twitter",
  97. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  98. "primary": true,
  99. "relocating_node": null,
  100. "shard": 2,
  101. "state": "STARTED"
  102. }
  103. ],
  104. [
  105. {
  106. "index": "twitter",
  107. "node": "JklnKbD7Tyqi9TP3_Q_tBg",
  108. "primary": true,
  109. "relocating_node": null,
  110. "shard": 4,
  111. "state": "STARTED"
  112. }
  113. ]
  114. ]
  115. }
  116. --------------------------------------------------
  117. This time the search will only be executed against two of the shards, because
  118. routing values have been specified.
  119. [float]
  120. === All parameters:
  121. [horizontal]
  122. `routing`::
  123. A comma-separated list of routing values to take into account when
  124. determining which shards a request would be executed against.
  125. `preference`::
  126. Controls a `preference` of which shard replicas to execute the search
  127. request on. By default, the operation is randomized between the shard
  128. replicas. See the link:search-request-preference.html[preference]
  129. documentation for a list of all acceptable values.
  130. `local`::
  131. A boolean value whether to read the cluster state locally in order to
  132. determine where shards are allocated instead of using the Master node's
  133. cluster state.