clone-index.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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,console]
  20. --------------------------------------------------
  21. PUT my_source_index
  22. {
  23. "settings": {
  24. "index.number_of_shards" : 5
  25. }
  26. }
  27. --------------------------------------------------
  28. In order to clone an index, the index must be marked as read-only,
  29. and have <<cluster-health,health>> `green`.
  30. This can be achieved with the following request:
  31. [source,console]
  32. --------------------------------------------------
  33. PUT /my_source_index/_settings
  34. {
  35. "settings": {
  36. "index.blocks.write": true <1>
  37. }
  38. }
  39. --------------------------------------------------
  40. // TEST[continued]
  41. <1> Prevents write operations to this index while still allowing metadata
  42. changes like deleting the index.
  43. [float]
  44. ==== Cloning an index
  45. To clone `my_source_index` into a new index called `my_target_index`, issue
  46. the following request:
  47. [source,console]
  48. --------------------------------------------------
  49. POST my_source_index/_clone/my_target_index
  50. --------------------------------------------------
  51. // TEST[continued]
  52. The above request returns immediately once the target index has been added to
  53. the cluster state -- it doesn't wait for the clone operation to start.
  54. [IMPORTANT]
  55. =====================================
  56. Indices can only be cloned if they satisfy the following requirements:
  57. * the target index must not exist
  58. * The source index must have the same number of primary shards as the target index.
  59. * The node handling the clone process must have sufficient free disk space to
  60. accommodate a second copy of the existing index.
  61. =====================================
  62. The `_clone` API is similar to the <<indices-create-index, `create index` API>>
  63. and accepts `settings` and `aliases` parameters for the target index:
  64. [source,console]
  65. --------------------------------------------------
  66. POST my_source_index/_clone/my_target_index
  67. {
  68. "settings": {
  69. "index.number_of_shards": 5 <1>
  70. },
  71. "aliases": {
  72. "my_search_indices": {}
  73. }
  74. }
  75. --------------------------------------------------
  76. // TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "5"}}\n/]
  77. <1> The number of shards in the target index. This must be equal to the
  78. number of shards in the source index.
  79. NOTE: Mappings may not be specified in the `_clone` request. The mappings of
  80. the source index will be used for the target index.
  81. [float]
  82. ==== Monitoring the clone process
  83. The clone process can be monitored with the <<cat-recovery,`_cat recovery`
  84. API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
  85. until all primary shards have been allocated by setting the `wait_for_status`
  86. parameter to `yellow`.
  87. The `_clone` API returns as soon as the target index has been added to the
  88. cluster state, before any shards have been allocated. At this point, all
  89. shards are in the state `unassigned`. If, for any reason, the target index
  90. can't be allocated, its primary shard will remain `unassigned` until it
  91. can be allocated on that node.
  92. Once the primary shard is allocated, it moves to state `initializing`, and the
  93. clone process begins. When the clone operation completes, the shard will
  94. become `active`. At that point, Elasticsearch will try to allocate any
  95. replicas and may decide to relocate the primary shard to another node.
  96. [float]
  97. ==== Wait For Active Shards
  98. Because the clone operation creates a new index to clone the shards to,
  99. the <<create-index-wait-for-active-shards,wait for active shards>> setting
  100. on index creation applies to the clone index action as well.