clone-index.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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
  43. to clone an existing index into a new index,
  44. where each original primary shard is cloned
  45. into a new primary shard in the new index.
  46. [[cloning-works]]
  47. ===== How cloning works
  48. Cloning works as follows:
  49. * First, it creates a new target index with the same definition as the source
  50. index.
  51. * Then it hard-links segments from the source index into the target index. (If
  52. the file system doesn't support hard-linking, then all segments are copied
  53. into the new index, which is a much more time consuming process.)
  54. * Finally, it recovers the target index as though it were a closed index which
  55. had just been re-opened.
  56. [[clone-index]]
  57. ===== Clone an index
  58. To clone `my_source_index` into a new index called `my_target_index`, issue
  59. the following request:
  60. [source,console]
  61. --------------------------------------------------
  62. POST /my_source_index/_clone/my_target_index
  63. --------------------------------------------------
  64. // TEST[continued]
  65. The above request returns immediately once the target index has been added to
  66. the cluster state -- it doesn't wait for the clone operation to start.
  67. [IMPORTANT]
  68. =====================================
  69. Indices can only be cloned if they meet the following requirements:
  70. * The target index must not exist.
  71. * The source index must have the same number of primary shards as the target index.
  72. * The node handling the clone process must have sufficient free disk space to
  73. accommodate a second copy of the existing index.
  74. =====================================
  75. The `_clone` API is similar to the <<indices-create-index, `create index` API>>
  76. and accepts `settings` and `aliases` parameters for the target index:
  77. [source,console]
  78. --------------------------------------------------
  79. POST /my_source_index/_clone/my_target_index
  80. {
  81. "settings": {
  82. "index.number_of_shards": 5 <1>
  83. },
  84. "aliases": {
  85. "my_search_indices": {}
  86. }
  87. }
  88. --------------------------------------------------
  89. // TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "5"}}\n/]
  90. <1> The number of shards in the target index. This must be equal to the
  91. number of shards in the source index.
  92. NOTE: Mappings may not be specified in the `_clone` request. The mappings of
  93. the source index will be used for the target index.
  94. [[monitor-cloning]]
  95. ===== Monitor the cloning process
  96. The cloning process can be monitored with the <<cat-recovery,`_cat recovery`
  97. API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
  98. until all primary shards have been allocated by setting the `wait_for_status`
  99. parameter to `yellow`.
  100. The `_clone` API returns as soon as the target index has been added to the
  101. cluster state, before any shards have been allocated. At this point, all
  102. shards are in the state `unassigned`. If, for any reason, the target index
  103. can't be allocated, its primary shard will remain `unassigned` until it
  104. can be allocated on that node.
  105. Once the primary shard is allocated, it moves to state `initializing`, and the
  106. clone process begins. When the clone operation completes, the shard will
  107. become `active`. At that point, {es} will try to allocate any
  108. replicas and may decide to relocate the primary shard to another node.
  109. [[clone-wait-active-shards]]
  110. ===== Wait for active shards
  111. Because the clone operation creates a new index to clone the shards to,
  112. the <<create-index-wait-for-active-shards,wait for active shards>> setting
  113. on index creation applies to the clone index action as well.
  114. [[clone-index-api-path-params]]
  115. ==== {api-path-parms-title}
  116. `<index>`::
  117. (Required, string)
  118. Name of the source index to clone.
  119. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index]
  120. [[clone-index-api-query-params]]
  121. ==== {api-query-parms-title}
  122. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
  123. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  124. [[clone-index-api-request-body]]
  125. ==== {api-request-body-title}
  126. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index-aliases]
  127. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index-settings]