1
1
[[indices-clone-index]]
2
- === Clone Index
2
+ === Clone index API
3
+ ++++
4
+ <titleabbrev>Clone index</titleabbrev>
5
+ ++++
3
6
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.
7
8
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/]
10
14
11
- Cloning works as follows:
12
15
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}
15
18
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>`
19
20
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>`
22
22
23
- [float]
24
- ==== Preparing an index for cloning
25
23
26
- Create a new index:
24
+ [[clone-index-api-prereqs]]
25
+ ==== {api-prereq-title}
27
26
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`.
41
30
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.
43
35
44
- [source,js ]
36
+ [source,console ]
45
37
--------------------------------------------------
46
38
PUT /my_source_index/_settings
47
39
{
48
40
"settings": {
49
- "index.blocks.write": true <1>
41
+ "index.blocks.write": true
50
42
}
51
43
}
52
44
--------------------------------------------------
53
- // CONSOLE
54
- // TEST[continued]
45
+ // TEST[s/^/PUT my_source_index\n/]
55
46
56
- <1> Prevents write operations to this index while still allowing metadata
57
- changes like deleting the index.
58
47
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
61
73
62
74
To clone `my_source_index` into a new index called `my_target_index`, issue
63
75
the following request:
64
76
65
- [source,js ]
77
+ [source,console ]
66
78
--------------------------------------------------
67
- POST my_source_index/_clone/my_target_index
79
+ POST / my_source_index/_clone/my_target_index
68
80
--------------------------------------------------
69
- // CONSOLE
70
81
// TEST[continued]
71
82
72
83
The 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.
75
86
[IMPORTANT]
76
87
=====================================
77
88
78
- Indices can only be cloned if they satisfy the following requirements:
89
+ Indices can only be cloned if they meet the following requirements:
79
90
80
- * the target index must not exist
91
+ * The target index must not exist.
81
92
82
93
* The source index must have the same number of primary shards as the target index.
83
94
@@ -89,9 +100,9 @@ Indices can only be cloned if they satisfy the following requirements:
89
100
The `_clone` API is similar to the <<indices-create-index, `create index` API>>
90
101
and accepts `settings` and `aliases` parameters for the target index:
91
102
92
- [source,js ]
103
+ [source,console ]
93
104
--------------------------------------------------
94
- POST my_source_index/_clone/my_target_index
105
+ POST / my_source_index/_clone/my_target_index
95
106
{
96
107
"settings": {
97
108
"index.number_of_shards": 5 <1>
@@ -101,7 +112,6 @@ POST my_source_index/_clone/my_target_index
101
112
}
102
113
}
103
114
--------------------------------------------------
104
- // CONSOLE
105
115
// TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "5"}}\n/]
106
116
107
117
<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
111
121
NOTE: Mappings may not be specified in the `_clone` request. The mappings of
112
122
the source index will be used for the target index.
113
123
114
- [float ]
115
- ==== Monitoring the clone process
124
+ [[monitor-cloning] ]
125
+ ===== Monitor the cloning process
116
126
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`
118
128
API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
119
129
until all primary shards have been allocated by setting the `wait_for_status`
120
130
parameter to `yellow`.
@@ -127,12 +137,38 @@ can be allocated on that node.
127
137
128
138
Once the primary shard is allocated, it moves to state `initializing`, and the
129
139
clone 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
131
141
replicas and may decide to relocate the primary shard to another node.
132
142
133
- [float ]
134
- ==== Wait For Active Shards
143
+ [[clone-wait-active-shards] ]
144
+ ===== Wait for active shards
135
145
136
146
Because the clone operation creates a new index to clone the shards to,
137
147
the <<create-index-wait-for-active-shards,wait for active shards>> setting
138
148
on 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