clone-index.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. [[indices-clone-index]]
  2. === Clone Index
  3. The clone index API allows you to clone an existing index into a new index,
  4. where each original primary shard is cloned into a new primary shard in
  5. the new index.
  6. [float]
  7. ==== How does cloning work?
  8. Cloning works as follows:
  9. * First, it creates a new target index with the same definition as the source
  10. index.
  11. * Then it hard-links segments from the source index into the target index. (If
  12. the file system doesn't support hard-linking, then all segments are copied
  13. into the new index, which is a much more time consuming process.)
  14. * Finally, it recovers the target index as though it were a closed index which
  15. had just been re-opened.
  16. [float]
  17. ==== Preparing an index for cloning
  18. Create a new index:
  19. [source,js]
  20. --------------------------------------------------
  21. PUT my_source_index
  22. {
  23. "settings": {
  24. "index.number_of_shards" : 5
  25. }
  26. }
  27. --------------------------------------------------
  28. // CONSOLE
  29. In order to clone an index, the index must be marked as read-only,
  30. and have <<cluster-health,health>> `green`.
  31. This can be achieved with the following request:
  32. [source,js]
  33. --------------------------------------------------
  34. PUT /my_source_index/_settings
  35. {
  36. "settings": {
  37. "index.blocks.write": true <1>
  38. }
  39. }
  40. --------------------------------------------------
  41. // CONSOLE
  42. // TEST[continued]
  43. <1> Prevents write operations to this index while still allowing metadata
  44. changes like deleting the index.
  45. [float]
  46. ==== Cloning an index
  47. To clone `my_source_index` into a new index called `my_target_index`, issue
  48. the following request:
  49. [source,js]
  50. --------------------------------------------------
  51. POST my_source_index/_clone/my_target_index
  52. --------------------------------------------------
  53. // CONSOLE
  54. // TEST[continued]
  55. The above request returns immediately once the target index has been added to
  56. the cluster state -- it doesn't wait for the clone operation to start.
  57. [IMPORTANT]
  58. =====================================
  59. Indices can only be cloned if they satisfy the following requirements:
  60. * the target index must not exist
  61. * The source index must have the same number of primary shards as the target index.
  62. * The node handling the clone process must have sufficient free disk space to
  63. accommodate a second copy of the existing index.
  64. =====================================
  65. The `_clone` API is similar to the <<indices-create-index, `create index` API>>
  66. and accepts `settings` and `aliases` parameters for the target index:
  67. [source,js]
  68. --------------------------------------------------
  69. POST my_source_index/_clone/my_target_index
  70. {
  71. "settings": {
  72. "index.number_of_shards": 5 <1>
  73. },
  74. "aliases": {
  75. "my_search_indices": {}
  76. }
  77. }
  78. --------------------------------------------------
  79. // CONSOLE
  80. // TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "5"}}\n/]
  81. <1> The number of shards in the target index. This must be equal to the
  82. number of shards in the source index.
  83. NOTE: Mappings may not be specified in the `_clone` request. The mappings of
  84. the source index will be used for the target index.
  85. [float]
  86. ==== Monitoring the clone process
  87. The clone process can be monitored with the <<cat-recovery,`_cat recovery`
  88. API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
  89. until all primary shards have been allocated by setting the `wait_for_status`
  90. parameter to `yellow`.
  91. The `_clone` API returns as soon as the target index has been added to the
  92. cluster state, before any shards have been allocated. At this point, all
  93. shards are in the state `unassigned`. If, for any reason, the target index
  94. can't be allocated, its primary shard will remain `unassigned` until it
  95. can be allocated on that node.
  96. Once the primary shard is allocated, it moves to state `initializing`, and the
  97. clone process begins. When the clone operation completes, the shard will
  98. become `active`. At that point, Elasticsearch will try to allocate any
  99. replicas and may decide to relocate the primary shard to another node.
  100. [float]
  101. ==== Wait For Active Shards
  102. Because the clone operation creates a new index to clone the shards to,
  103. the <<create-index-wait-for-active-shards,wait for active shards>> setting
  104. on index creation applies to the clone index action as well.