clone-index.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. [[indices-clone-index]]
  2. === Clone index API
  3. ++++
  4. <titleabbrev>Clone index</titleabbrev>
  5. ++++
  6. Clones an existing index.
  7. [source,console]
  8. --------------------------------------------------
  9. POST /my-index-000001/_clone/cloned-my-index-000001
  10. --------------------------------------------------
  11. // TEST[s/^/PUT my-index-000001\n{"settings":{"index.number_of_shards" : 5,"blocks.write":true}}\n/]
  12. [[clone-index-api-request]]
  13. ==== {api-request-title}
  14. `POST /<index>/_clone/<target-index>`
  15. `PUT /<index>/_clone/<target-index>`
  16. [[clone-index-api-prereqs]]
  17. ==== {api-prereq-title}
  18. * If the {es} {security-features} are enabled, you must have the `manage`
  19. <<privileges-list-indices,index privilege>> for the index you want to clone.
  20. * To clone an index, the index must be marked as read-only and have a
  21. <<cluster-health,cluster health>> status of `green`.
  22. For example,
  23. the following request prevents write operations on `my_source_index`
  24. so it can be cloned.
  25. Metadata changes like deleting the index are still allowed.
  26. [source,console]
  27. --------------------------------------------------
  28. PUT /my_source_index/_settings
  29. {
  30. "settings": {
  31. "index.blocks.write": true
  32. }
  33. }
  34. --------------------------------------------------
  35. // TEST[s/^/PUT my_source_index\n/]
  36. The current write index on a data stream cannot be cloned. In order to clone
  37. the current write index, the data stream must first be
  38. <<data-streams-rollover,rolled over>> so that a new write index is created
  39. and then the previous write index can be cloned.
  40. [[clone-index-api-desc]]
  41. ==== {api-description-title}
  42. Use the clone index API to clone an existing index into a new index, where each
  43. original primary shard is cloned into a new primary shard in the new index.
  44. [IMPORTANT]
  45. ====
  46. {es} doesn't apply index templates to the resulting index. The API
  47. also doesn't copy index metadata from the original index. Index metadata
  48. includes aliases, {ilm-init} phase definitions, and {ccr-init} follower
  49. information. For example, if you clone a {ccr-init} follower index, the
  50. resulting clone won't be a follower index.
  51. The clone API copies most index settings from the source index to the resulting
  52. index, with the exception of `index.number_of_replicas` and
  53. `index.auto_expand_replicas`. To set the number of replicas in the resulting
  54. index, configure these settings in the clone request.
  55. ====
  56. [[cloning-works]]
  57. ===== How cloning works
  58. Cloning works as follows:
  59. * First, it creates a new target index with the same definition as the source
  60. index.
  61. * Then it hard-links segments from the source index into the target index. (If
  62. the file system doesn't support hard-linking, then all segments are copied
  63. into the new index, which is a much more time consuming process.)
  64. * Finally, it recovers the target index as though it were a closed index which
  65. had just been re-opened.
  66. [[clone-index]]
  67. ===== Clone an index
  68. To clone `my_source_index` into a new index called `my_target_index`, issue
  69. the following request:
  70. [source,console]
  71. --------------------------------------------------
  72. POST /my_source_index/_clone/my_target_index
  73. --------------------------------------------------
  74. // TEST[continued]
  75. The above request returns immediately once the target index has been added to
  76. the cluster state -- it doesn't wait for the clone operation to start.
  77. [IMPORTANT]
  78. =====================================
  79. Indices can only be cloned if they meet the following requirements:
  80. * The target index must not exist.
  81. * The source index must have the same number of primary shards as the target index.
  82. * The node handling the clone process must have sufficient free disk space to
  83. accommodate a second copy of the existing index.
  84. =====================================
  85. The `_clone` API is similar to the <<indices-create-index, `create index` API>>
  86. and accepts `settings` and `aliases` parameters for the target index:
  87. [source,console]
  88. --------------------------------------------------
  89. POST /my_source_index/_clone/my_target_index
  90. {
  91. "settings": {
  92. "index.number_of_shards": 5 <1>
  93. },
  94. "aliases": {
  95. "my_search_indices": {}
  96. }
  97. }
  98. --------------------------------------------------
  99. // TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "5"}}\n/]
  100. <1> The number of shards in the target index. This must be equal to the
  101. number of shards in the source index.
  102. NOTE: Mappings may not be specified in the `_clone` request. The mappings of
  103. the source index will be used for the target index.
  104. [[monitor-cloning]]
  105. ===== Monitor the cloning process
  106. The cloning process can be monitored with the <<cat-recovery,`_cat recovery`
  107. API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
  108. until all primary shards have been allocated by setting the `wait_for_status`
  109. parameter to `yellow`.
  110. The `_clone` API returns as soon as the target index has been added to the
  111. cluster state, before any shards have been allocated. At this point, all
  112. shards are in the state `unassigned`. If, for any reason, the target index
  113. can't be allocated, its primary shard will remain `unassigned` until it
  114. can be allocated on that node.
  115. Once the primary shard is allocated, it moves to state `initializing`, and the
  116. clone process begins. When the clone operation completes, the shard will
  117. become `active`. At that point, {es} will try to allocate any
  118. replicas and may decide to relocate the primary shard to another node.
  119. [[clone-wait-active-shards]]
  120. ===== Wait for active shards
  121. Because the clone operation creates a new index to clone the shards to,
  122. the <<create-index-wait-for-active-shards,wait for active shards>> setting
  123. on index creation applies to the clone index action as well.
  124. [[clone-index-api-path-params]]
  125. ==== {api-path-parms-title}
  126. `<index>`::
  127. (Required, string)
  128. Name of the source index to clone.
  129. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index]
  130. [[clone-index-api-query-params]]
  131. ==== {api-query-parms-title}
  132. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
  133. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  134. [role="child_attributes"]
  135. [[clone-index-api-request-body]]
  136. ==== {api-request-body-title}
  137. `aliases`::
  138. (Optional, object of objects) Aliases for the resulting index.
  139. +
  140. include::{es-repo-dir}/indices/create-index.asciidoc[tag=aliases-props]
  141. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index-settings]