clone-index.asciidoc 5.4 KB

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