44<titleabbrev>Split index</titleabbrev>
55++++
66
7+ Splits an existing index into a new index with more primary shards.
8+
9+ [source,console]
10+ ----
11+ POST /twitter/_split/split-twitter-index
12+ {
13+ "settings": {
14+ "index.number_of_shards": 2
15+ }
16+ }
17+ ----
18+ // TEST[s/^/PUT twitter\n{"settings":{"blocks.write":true}}\n/]
19+
20+
21+ [[split-index-api-request]]
22+ ==== {api-request-title}
23+
24+ `POST /<index>/_shrink/<target-index>`
25+
26+ `PUT /<index>/_shrink/<target-index>`
27+
28+
29+ [[split-index-api-prereqs]]
30+ ==== {api-prereq-title}
31+
32+
33+ Before you can split an index:
34+
35+ * The index must be read-only.
36+ * The <<cluster-health, cluster health>> status must be green.
37+
38+ You can do make an index read-only
39+ with the following request:
40+
41+ [source,console]
42+ --------------------------------------------------
43+ PUT /my_source_index/_settings
44+ {
45+ "settings": {
46+ "index.blocks.write": true <1>
47+ }
48+ }
49+ --------------------------------------------------
50+ // TEST[s/^/PUT my_source_index\n/]
51+
52+ <1> Prevents write operations to this index while still allowing metadata
53+ changes like deleting the index.
54+
55+
56+ [[split-index-api-desc]]
57+ ==== {api-description-title}
58+
759The split index API allows you to split an existing index into a new index,
860where each original primary shard is split into two or more primary shards in
961the new index.
@@ -34,27 +86,28 @@ index may by split into an arbitrary number of shards greater than 1. The
3486properties of the default number of routing shards will then apply to the
3587newly split index.
3688
37- [float]
38- ==== How does splitting work?
3989
40- Splitting works as follows:
90+ [[how-split-works]]
91+ ===== How splitting works
4192
42- * First, it creates a new target index with the same definition as the source
93+ A split operation:
94+
95+ . Creates a new target index with the same definition as the source
4396 index, but with a larger number of primary shards.
4497
45- * Then it hard -links segments from the source index into the target index. (If
98+ . Hard -links segments from the source index into the target index. (If
4699 the file system doesn't support hard-linking, then all segments are copied
47100 into the new index, which is a much more time consuming process.)
48101
49- * Once the low level files are created all documents will be `hashed` again to delete
102+ . Hashes all documents again, after low level files are created, to delete
50103 documents that belong to a different shard.
51104
52- * Finally, it recovers the target index as though it were a closed index which
105+ . Recovers the target index as though it were a closed index which
53106 had just been re-opened.
54107
55- [float]
108+
56109[[incremental-resharding]]
57- ==== Why doesn't Elasticsearch support incremental resharding?
110+ ===== Why doesn't Elasticsearch support incremental resharding?
58111
59112Going from `N` shards to `N+1` shards, aka. incremental resharding, is indeed a
60113feature that is supported by many key-value stores. Adding a new shard and
@@ -83,58 +136,22 @@ covers both the old and the new index for read operations. Assuming that the
83136old and new indices have respectively +M+ and +N+ shards, this has no overhead
84137compared to searching an index that would have +M+N+ shards.
85138
86- [float]
87- ==== Preparing an index for splitting
88-
89- Create a new index:
90-
91- [source,js]
92- --------------------------------------------------
93- PUT my_source_index
94- {
95- "settings": {
96- "index.number_of_shards" : 1
97- }
98- }
99- --------------------------------------------------
100- // CONSOLE
101-
102- In order to split an index, the index must be marked as read-only,
103- and have <<cluster-health,health>> `green`.
104139
105- This can be achieved with the following request:
106-
107- [source,js]
108- --------------------------------------------------
109- PUT /my_source_index/_settings
110- {
111- "settings": {
112- "index.blocks.write": true <1>
113- }
114- }
115- --------------------------------------------------
116- // CONSOLE
117- // TEST[continued]
118-
119- <1> Prevents write operations to this index while still allowing metadata
120- changes like deleting the index.
121-
122- [float]
123- ==== Splitting an index
140+ [[split-index]]
141+ ===== Split an index
124142
125143To split `my_source_index` into a new index called `my_target_index`, issue
126144the following request:
127145
128- [source,js ]
146+ [source,console ]
129147--------------------------------------------------
130- POST my_source_index/_split/my_target_index
148+ POST / my_source_index/_split/my_target_index
131149{
132150 "settings": {
133151 "index.number_of_shards": 2
134152 }
135153}
136154--------------------------------------------------
137- // CONSOLE
138155// TEST[continued]
139156
140157The above request returns immediately once the target index has been added to
@@ -160,9 +177,9 @@ Indices can only be split if they satisfy the following requirements:
160177The `_split` API is similar to the <<indices-create-index, `create index` API>>
161178and accepts `settings` and `aliases` parameters for the target index:
162179
163- [source,js ]
180+ [source,console ]
164181--------------------------------------------------
165- POST my_source_index/_split/my_target_index
182+ POST / my_source_index/_split/my_target_index
166183{
167184 "settings": {
168185 "index.number_of_shards": 5 <1>
@@ -172,7 +189,6 @@ POST my_source_index/_split/my_target_index
172189 }
173190}
174191--------------------------------------------------
175- // CONSOLE
176192// TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "1"}}\n/]
177193
178194<1> The number of shards in the target index. This must be a factor of the
@@ -181,8 +197,9 @@ POST my_source_index/_split/my_target_index
181197
182198NOTE: Mappings may not be specified in the `_split` request.
183199
184- [float]
185- ==== Monitoring the split process
200+
201+ [[monitor-split]]
202+ ==== Monitor the split process
186203
187204The split process can be monitored with the <<cat-recovery,`_cat recovery`
188205API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
@@ -200,9 +217,36 @@ split process begins. When the split operation completes, the shard will
200217become `active`. At that point, Elasticsearch will try to allocate any
201218replicas and may decide to relocate the primary shard to another node.
202219
203- [float]
204- ==== Wait For Active Shards
220+
221+ [[split-wait-active-shards]]
222+ ==== Wait for active shards
205223
206224Because the split operation creates a new index to split the shards to,
207225the <<create-index-wait-for-active-shards,wait for active shards>> setting
208226on index creation applies to the split index action as well.
227+
228+
229+ [[split-index-api-path-params]]
230+ ==== {api-path-parms-title}
231+
232+ `<index>`::
233+ (Required, string)
234+ Name of the source index to split.
235+
236+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index]
237+
238+
239+ [[split-index-api-query-params]]
240+ ==== {api-query-parms-title}
241+
242+ include::{docdir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
243+
244+ include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
245+
246+
247+ [[split-index-api-request-body]]
248+ ==== {api-request-body-title}
249+
250+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-aliases]
251+
252+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-settings]
0 commit comments