11[[indices-clone-index]]
2- === Clone Index
2+ === Clone index API
3+ ++++
4+ <titleabbrev>Clone index</titleabbrev>
5+ ++++
36
4- The clone index API allows you to clone an existing index into a new index,
5- where each original primary shard is cloned into a new primary shard in
6- the new index.
7+ Clones an existing index.
78
8- [float]
9- ==== How does cloning work?
10-
11- Cloning works as follows:
9+ [source,console]
10+ --------------------------------------------------
11+ POST /twitter/_clone/cloned-twitter-index
12+ --------------------------------------------------
13+ // TEST[s/^/PUT twitter\n{"settings":{"index.number_of_shards" : 5,"blocks.write":true}}\n/]
1214
13- * First, it creates a new target index with the same definition as the source
14- index.
1515
16- * Then it hard-links segments from the source index into the target index. (If
17- the file system doesn't support hard-linking, then all segments are copied
18- into the new index, which is a much more time consuming process.)
16+ [[clone-index-api-request]]
17+ ==== {api-request-title}
1918
20- * Finally, it recovers the target index as though it were a closed index which
21- had just been re-opened.
19+ `POST /<index>/_clone/<target-index>`
2220
23- [float]
24- ==== Preparing an index for cloning
21+ `PUT /<index>/_clone/<target-index>`
2522
26- Create a new index:
2723
28- [source,console]
29- --------------------------------------------------
30- PUT my_source_index
31- {
32- "settings": {
33- "index.number_of_shards" : 5
34- }
35- }
36- --------------------------------------------------
24+ [[clone-index-api-prereqs]]
25+ ==== {api-prereq-title}
3726
38- In order to clone an index, the index must be marked as read-only,
39- and have <<cluster-health,health>> `green`.
27+ To clone an index,
28+ the index must be marked as read-only
29+ and have a <<cluster-health,cluster health>> status of `green`.
4030
41- This can be achieved with the following request:
31+ For example,
32+ the following request prevents write operations on `my_source_index`
33+ so it can be cloned.
34+ Metadata changes like deleting the index are still allowed.
4235
4336[source,console]
4437--------------------------------------------------
4538PUT /my_source_index/_settings
4639{
4740 "settings": {
48- "index.blocks.write": true <1>
41+ "index.blocks.write": true
4942 }
5043}
5144--------------------------------------------------
52- // TEST[continued]
45+ // TEST[s/^/PUT my_source_index\n/]
46+
5347
54- <1> Prevents write operations to this index while still allowing metadata
55- changes like deleting the index.
48+ [[clone- index-api-desc]]
49+ ==== {api-description-title}
5650
57- [float]
58- ==== Cloning an index
51+ Use the clone index API
52+ to clone an existing index into a new index,
53+ where each original primary shard is cloned
54+ into a new primary shard in the new index.
55+
56+ [[cloning-works]]
57+ ===== How cloning works
58+
59+ Cloning works as follows:
60+
61+ * First, it creates a new target index with the same definition as the source
62+ index.
63+
64+ * Then it hard-links segments from the source index into the target index. (If
65+ the file system doesn't support hard-linking, then all segments are copied
66+ into the new index, which is a much more time consuming process.)
67+
68+ * Finally, it recovers the target index as though it were a closed index which
69+ had just been re-opened.
70+
71+ [[clone-index]]
72+ ===== Clone an index
5973
6074To clone `my_source_index` into a new index called `my_target_index`, issue
6175the following request:
6276
6377[source,console]
6478--------------------------------------------------
65- POST my_source_index/_clone/my_target_index
79+ POST / my_source_index/_clone/my_target_index
6680--------------------------------------------------
6781// TEST[continued]
6882
@@ -72,9 +86,9 @@ the cluster state -- it doesn't wait for the clone operation to start.
7286[IMPORTANT]
7387=====================================
7488
75- Indices can only be cloned if they satisfy the following requirements:
89+ Indices can only be cloned if they meet the following requirements:
7690
77- * the target index must not exist
91+ * The target index must not exist.
7892
7993* The source index must have the same number of primary shards as the target index.
8094
@@ -88,7 +102,7 @@ and accepts `settings` and `aliases` parameters for the target index:
88102
89103[source,console]
90104--------------------------------------------------
91- POST my_source_index/_clone/my_target_index
105+ POST / my_source_index/_clone/my_target_index
92106{
93107 "settings": {
94108 "index.number_of_shards": 5 <1>
@@ -107,10 +121,10 @@ POST my_source_index/_clone/my_target_index
107121NOTE: Mappings may not be specified in the `_clone` request. The mappings of
108122the source index will be used for the target index.
109123
110- [float ]
111- ==== Monitoring the clone process
124+ [[monitor-cloning] ]
125+ ===== Monitor the cloning process
112126
113- The clone process can be monitored with the <<cat-recovery,`_cat recovery`
127+ The cloning process can be monitored with the <<cat-recovery,`_cat recovery`
114128API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
115129until all primary shards have been allocated by setting the `wait_for_status`
116130parameter to `yellow`.
@@ -123,12 +137,38 @@ can be allocated on that node.
123137
124138Once the primary shard is allocated, it moves to state `initializing`, and the
125139clone process begins. When the clone operation completes, the shard will
126- become `active`. At that point, Elasticsearch will try to allocate any
140+ become `active`. At that point, {es} will try to allocate any
127141replicas and may decide to relocate the primary shard to another node.
128142
129- [float ]
130- ==== Wait For Active Shards
143+ [[clone-wait-active-shards] ]
144+ ===== Wait for active shards
131145
132146Because the clone operation creates a new index to clone the shards to,
133147the <<create-index-wait-for-active-shards,wait for active shards>> setting
134148on index creation applies to the clone index action as well.
149+
150+
151+ [[clone-index-api-path-params]]
152+ ==== {api-path-parms-title}
153+
154+ `<index>`::
155+ (Required, string)
156+ Name of the source index to clone.
157+
158+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index]
159+
160+
161+ [[clone-index-api-query-params]]
162+ ==== {api-query-parms-title}
163+
164+ include::{docdir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
165+
166+ include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
167+
168+
169+ [[clone-index-api-request-body]]
170+ ==== {api-request-body-title}
171+
172+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-aliases]
173+
174+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-settings]
0 commit comments