reroute.asciidoc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. [[cluster-reroute]]
  2. === Cluster reroute API
  3. ++++
  4. <titleabbrev>Cluster reroute</titleabbrev>
  5. ++++
  6. .New API reference
  7. [sidebar]
  8. --
  9. For the most up-to-date API details, refer to {api-es}/group/endpoint-cluster[Cluster APIs].
  10. --
  11. Changes the allocation of shards in a cluster.
  12. [[cluster-reroute-api-request]]
  13. ==== {api-request-title}
  14. `POST /_cluster/reroute?metric=none`
  15. [[cluster-reroute-api-prereqs]]
  16. ==== {api-prereq-title}
  17. * If the {es} {security-features} are enabled, you must have the `manage`
  18. <<privileges-list-cluster,cluster privilege>> to use this API.
  19. [[cluster-reroute-api-desc]]
  20. ==== {api-description-title}
  21. The reroute command allows for manual changes to the allocation of individual
  22. shards in the cluster. For example, a shard can be moved from one node to
  23. another explicitly, an allocation can be cancelled, and an unassigned shard can
  24. be explicitly allocated to a specific node.
  25. It is important to note that after processing any reroute commands {es} will
  26. perform rebalancing as normal (respecting the values of settings such as
  27. `cluster.routing.rebalance.enable`) in order to remain in a balanced state. For
  28. example, if the requested allocation includes moving a shard from `node1` to
  29. `node2` then this may cause a shard to be moved from `node2` back to `node1` to
  30. even things out.
  31. The cluster can be set to disable allocations using the
  32. `cluster.routing.allocation.enable` setting. If allocations are disabled then
  33. the only allocations that will be performed are explicit ones given using the
  34. `reroute` command, and consequent allocations due to rebalancing.
  35. It is possible to run `reroute` commands in "dry run" mode by using the
  36. `?dry_run` URI query parameter, or by passing `"dry_run": true` in the request
  37. body. This will calculate the result of applying the commands to the current
  38. cluster state, and return the resulting cluster state after the commands (and
  39. re-balancing) has been applied, but will not actually perform the requested
  40. changes.
  41. If the `?explain` URI query parameter is included then a detailed explanation
  42. of why the commands could or could not be executed is included in the response.
  43. The cluster will attempt to allocate a shard a maximum of
  44. `index.allocation.max_retries` times in a row (defaults to `5`), before giving
  45. up and leaving the shard unallocated. This scenario can be caused by
  46. structural problems such as having an analyzer which refers to a stopwords
  47. file which doesn't exist on all nodes.
  48. Once the problem has been corrected, allocation can be manually retried by
  49. calling the `reroute` API with the `?retry_failed` URI
  50. query parameter, which will attempt a single retry round for these shards.
  51. [[cluster-reroute-api-query-params]]
  52. [role="child_attributes"]
  53. ==== {api-query-parms-title}
  54. `dry_run`::
  55. (Optional, Boolean) If `true`, then the request simulates the operation only
  56. and returns the resulting state.
  57. `explain`::
  58. (Optional, Boolean) If `true`, then the response contains an explanation of
  59. why the commands can or cannot be executed.
  60. `metric`::
  61. (Optional, string) Limits the information returned to the specified metrics.
  62. All options except `none` are deprecated and should be avoided for this parameter.
  63. Defaults to all but metadata. The following options are available:
  64. +
  65. .Options for `metric`
  66. [%collapsible%open]
  67. ======
  68. `_all`::
  69. Shows all metrics.
  70. `blocks`::
  71. Shows the `blocks` part of the response.
  72. `master_node`::
  73. Shows the elected `master_node` part of the response.
  74. `metadata`::
  75. Shows the `metadata` part of the response. If you supply a comma separated
  76. list of indices, the returned output will only contain metadata for these
  77. indices.
  78. `nodes`::
  79. Shows the `nodes` part of the response.
  80. `none`::
  81. Excludes the entire `state` field from the response.
  82. `routing_table`::
  83. Shows the `routing_table` part of the response.
  84. `version`::
  85. Shows the cluster state version.
  86. ======
  87. `retry_failed`::
  88. (Optional, Boolean) If `true`, then retries allocation of shards that are
  89. blocked due to too many subsequent allocation failures.
  90. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  91. [role="child_attributes"]
  92. [[cluster-reroute-api-request-body]]
  93. ==== {api-request-body-title}
  94. `commands`::
  95. (Required, array of objects) Defines the commands to perform. Supported commands are:
  96. +
  97. .Properties of `commands`
  98. [%collapsible%open]
  99. ======
  100. `move`::
  101. Move a started shard from one node to another node. Accepts `index` and
  102. `shard` for index name and shard number, `from_node` for the node to move
  103. the shard from, and `to_node` for the node to move the shard to.
  104. `cancel`::
  105. Cancel allocation of a shard (or recovery). Accepts `index` and `shard` for
  106. index name and shard number, and `node` for the node to cancel the shard
  107. allocation on. This can be used to force resynchronization of existing
  108. replicas from the primary shard by cancelling them and allowing them to be
  109. reinitialized through the standard recovery process. By default only
  110. replica shard allocations can be cancelled. If it is necessary to cancel
  111. the allocation of a primary shard then the `allow_primary` flag must also
  112. be included in the request.
  113. `allocate_replica`::
  114. Allocate an unassigned replica shard to a node. Accepts `index` and `shard`
  115. for index name and shard number, and `node` to allocate the shard to. Takes
  116. <<modules-cluster,allocation deciders>> into account.
  117. Two more commands are available that allow the allocation of a primary shard to
  118. a node. These commands should however be used with extreme care, as primary
  119. shard allocation is usually fully automatically handled by {es}. Reasons why a
  120. primary shard cannot be automatically allocated include the
  121. following:
  122. - A new index was created but there is no node which satisfies the allocation
  123. deciders.
  124. - An up-to-date shard copy of the data cannot be found on the current data
  125. nodes in the cluster. To prevent data loss, the system does not automatically
  126. promote a stale shard copy to primary.
  127. The following two commands are dangerous and may result in data loss. They are
  128. meant to be used in cases where the original data can not be recovered and the
  129. cluster administrator accepts the loss. If you have suffered a temporary issue
  130. that can be fixed, please see the `retry_failed` flag described above. To
  131. emphasise: if these commands are performed and then a node joins the cluster
  132. that holds a copy of the affected shard then the copy on the newly-joined node
  133. will be deleted or overwritten.
  134. `allocate_stale_primary`::
  135. Allocate a primary shard to a node that holds a stale copy. Accepts the
  136. `index` and `shard` for index name and shard number, and `node` to allocate
  137. the shard to. Using this command may lead to data loss for the provided
  138. shard id. If a node which has the good copy of the data rejoins the cluster
  139. later on, that data will be deleted or overwritten with the data of the
  140. stale copy that was forcefully allocated with this command. To ensure that
  141. these implications are well-understood, this command requires the flag
  142. `accept_data_loss` to be explicitly set to `true`.
  143. `allocate_empty_primary`::
  144. Allocate an empty primary shard to a node. Accepts the `index` and `shard`
  145. for index name and shard number, and `node` to allocate the shard to. Using
  146. this command leads to a complete loss of all data that was indexed into
  147. this shard, if it was previously started. If a node which has a copy of the
  148. data rejoins the cluster later on, that data will be deleted. To ensure
  149. that these implications are well-understood, this command requires the flag
  150. `accept_data_loss` to be explicitly set to `true`.
  151. ======
  152. [[cluster-reroute-api-example]]
  153. ==== {api-examples-title}
  154. This is a short example of a simple reroute API call:
  155. [source,console]
  156. --------------------------------------------------
  157. POST /_cluster/reroute?metric=none
  158. {
  159. "commands": [
  160. {
  161. "move": {
  162. "index": "test", "shard": 0,
  163. "from_node": "node1", "to_node": "node2"
  164. }
  165. },
  166. {
  167. "allocate_replica": {
  168. "index": "test", "shard": 1,
  169. "node": "node3"
  170. }
  171. }
  172. ]
  173. }
  174. --------------------------------------------------
  175. // TEST[skip:doc tests run with only a single node]