reroute.asciidoc 7.6 KB

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