clone-index.asciidoc 5.2 KB

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