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?
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/]
1014
11- Cloning works as follows:
1215
13- * First, it creates a new target index with the same definition as the source
14- index.
16+ [[clone- index-api-request]]
17+ ==== {api-request-title}
1518
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.)
19+ `POST /<index>/_clone/<target-index>`
1920
20- * Finally, it recovers the target index as though it were a closed index which
21- had just been re-opened.
21+ `PUT /<index>/_clone/<target-index>`
2222
23- [float]
24- ==== Preparing an index for cloning
2523
26- Create a new index:
24+ [[clone-index-api-prereqs]]
25+ ==== {api-prereq-title}
2726
28- [source,js]
29- --------------------------------------------------
30- PUT my_source_index
31- {
32- "settings": {
33- "index.number_of_shards" : 5
34- }
35- }
36- --------------------------------------------------
37- // CONSOLE
38-
39- In order to clone an index, the index must be marked as read-only,
40- 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`.
4130
42- 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.
4335
44- [source,js ]
36+ [source,console ]
4537--------------------------------------------------
4638PUT /my_source_index/_settings
4739{
4840 "settings": {
49- "index.blocks.write": true <1>
41+ "index.blocks.write": true
5042 }
5143}
5244--------------------------------------------------
53- // CONSOLE
54- // TEST[continued]
45+ // TEST[s/^/PUT my_source_index\n/]
5546
56- <1> Prevents write operations to this index while still allowing metadata
57- changes like deleting the index.
5847
59- [float]
60- ==== Cloning an index
48+ [[clone-index-api-desc]]
49+ ==== {api-description-title}
50+
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
6173
6274To clone `my_source_index` into a new index called `my_target_index`, issue
6375the following request:
6476
65- [source,js ]
77+ [source,console ]
6678--------------------------------------------------
67- POST my_source_index/_clone/my_target_index
79+ POST / my_source_index/_clone/my_target_index
6880--------------------------------------------------
69- // CONSOLE
7081// TEST[continued]
7182
7283The above request returns immediately once the target index has been added to
@@ -75,9 +86,9 @@ the cluster state -- it doesn't wait for the clone operation to start.
7586[IMPORTANT]
7687=====================================
7788
78- Indices can only be cloned if they satisfy the following requirements:
89+ Indices can only be cloned if they meet the following requirements:
7990
80- * the target index must not exist
91+ * The target index must not exist.
8192
8293* The source index must have the same number of primary shards as the target index.
8394
@@ -89,9 +100,9 @@ Indices can only be cloned if they satisfy the following requirements:
89100The `_clone` API is similar to the <<indices-create-index, `create index` API>>
90101and accepts `settings` and `aliases` parameters for the target index:
91102
92- [source,js ]
103+ [source,console ]
93104--------------------------------------------------
94- POST my_source_index/_clone/my_target_index
105+ POST / my_source_index/_clone/my_target_index
95106{
96107 "settings": {
97108 "index.number_of_shards": 5 <1>
@@ -101,7 +112,6 @@ POST my_source_index/_clone/my_target_index
101112 }
102113}
103114--------------------------------------------------
104- // CONSOLE
105115// TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "5"}}\n/]
106116
107117<1> The number of shards in the target index. This must be equal to the
@@ -111,10 +121,10 @@ POST my_source_index/_clone/my_target_index
111121NOTE: Mappings may not be specified in the `_clone` request. The mappings of
112122the source index will be used for the target index.
113123
114- [float ]
115- ==== Monitoring the clone process
124+ [[monitor-cloning] ]
125+ ===== Monitor the cloning process
116126
117- 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`
118128API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
119129until all primary shards have been allocated by setting the `wait_for_status`
120130parameter to `yellow`.
@@ -127,12 +137,38 @@ can be allocated on that node.
127137
128138Once the primary shard is allocated, it moves to state `initializing`, and the
129139clone process begins. When the clone operation completes, the shard will
130- become `active`. At that point, Elasticsearch will try to allocate any
140+ become `active`. At that point, {es} will try to allocate any
131141replicas and may decide to relocate the primary shard to another node.
132142
133- [float ]
134- ==== Wait For Active Shards
143+ [[clone-wait-active-shards] ]
144+ ===== Wait for active shards
135145
136146Because the clone operation creates a new index to clone the shards to,
137147the <<create-index-wait-for-active-shards,wait for active shards>> setting
138148on 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