44<titleabbrev>Split index</titleabbrev>
55++++
66
7+ Splits an existing index into a new index with more primary shards.
8+
9+ [source,js]
10+ ----
11+ POST /twitter/_split/split-twitter-index
12+ {
13+ "settings": {
14+ "index.number_of_shards": 2
15+ }
16+ }
17+ ----
18+ // CONSOLE
19+ // TEST[s/^/PUT twitter\n{"settings":{"blocks.write":true}}\n/]
20+
21+
22+ [[split-index-api-request]]
23+ ==== {api-request-title}
24+
25+ `POST /<index>/_shrink/<target-index>`
26+
27+ `PUT /<index>/_shrink/<target-index>`
28+
29+
30+ [[split-index-api-prereqs]]
31+ ==== {api-prereq-title}
32+
33+
34+ Before you can split an index:
35+
36+ * The index must be read-only.
37+ * The <<cluster-health, cluster health>> status must be green.
38+
39+ You can do make an index read-only
40+ with the following request:
41+
42+ [source,js]
43+ --------------------------------------------------
44+ PUT /my_source_index/_settings
45+ {
46+ "settings": {
47+ "index.blocks.write": true <1>
48+ }
49+ }
50+ --------------------------------------------------
51+ // CONSOLE
52+ // TEST[s/^/PUT my_source_index\n/]
53+
54+ <1> Prevents write operations to this index while still allowing metadata
55+ changes like deleting the index.
56+
57+
58+ [[split-index-api-desc]]
59+ ==== {api-description-title}
60+
761The split index API allows you to split an existing index into a new index,
862where each original primary shard is split into two or more primary shards in
963the new index.
@@ -34,27 +88,28 @@ index may by split into an arbitrary number of shards greater than 1. The
3488properties of the default number of routing shards will then apply to the
3589newly split index.
3690
37- [float]
38- ==== How does splitting work?
3991
40- Splitting works as follows:
92+ [[how-split-works]]
93+ ===== How splitting works
4194
42- * First, it creates a new target index with the same definition as the source
95+ A split operation:
96+
97+ . Creates a new target index with the same definition as the source
4398 index, but with a larger number of primary shards.
4499
45- * Then it hard -links segments from the source index into the target index. (If
100+ . Hard -links segments from the source index into the target index. (If
46101 the file system doesn't support hard-linking, then all segments are copied
47102 into the new index, which is a much more time consuming process.)
48103
49- * Once the low level files are created all documents will be `hashed` again to delete
104+ . Hashes all documents again, after low level files are created, to delete
50105 documents that belong to a different shard.
51106
52- * Finally, it recovers the target index as though it were a closed index which
107+ . Recovers the target index as though it were a closed index which
53108 had just been re-opened.
54109
55- [float]
110+
56111[[incremental-resharding]]
57- ==== Why doesn't Elasticsearch support incremental resharding?
112+ ===== Why doesn't Elasticsearch support incremental resharding?
58113
59114Going from `N` shards to `N+1` shards, aka. incremental resharding, is indeed a
60115feature that is supported by many key-value stores. Adding a new shard and
@@ -83,51 +138,16 @@ covers both the old and the new index for read operations. Assuming that the
83138old and new indices have respectively +M+ and +N+ shards, this has no overhead
84139compared to searching an index that would have +M+N+ shards.
85140
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
101141
102- In order to split an index, the index must be marked as read-only,
103- and have <<cluster-health,health>> `green`.
104-
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
142+ [[split-index]]
143+ ===== Split an index
124144
125145To split `my_source_index` into a new index called `my_target_index`, issue
126146the following request:
127147
128148[source,js]
129149--------------------------------------------------
130- POST my_source_index/_split/my_target_index
150+ POST / my_source_index/_split/my_target_index
131151{
132152 "settings": {
133153 "index.number_of_shards": 2
@@ -162,7 +182,7 @@ and accepts `settings` and `aliases` parameters for the target index:
162182
163183[source,js]
164184--------------------------------------------------
165- POST my_source_index/_split/my_target_index
185+ POST / my_source_index/_split/my_target_index
166186{
167187 "settings": {
168188 "index.number_of_shards": 5 <1>
@@ -181,8 +201,9 @@ POST my_source_index/_split/my_target_index
181201
182202NOTE: Mappings may not be specified in the `_split` request.
183203
184- [float]
185- ==== Monitoring the split process
204+
205+ [[monitor-split]]
206+ ===== Monitor the split process
186207
187208The split process can be monitored with the <<cat-recovery,`_cat recovery`
188209API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
@@ -200,9 +221,36 @@ split process begins. When the split operation completes, the shard will
200221become `active`. At that point, Elasticsearch will try to allocate any
201222replicas and may decide to relocate the primary shard to another node.
202223
203- [float]
204- ==== Wait For Active Shards
224+
225+ [[split-wait-active-shards]]
226+ ===== Wait for active shards
205227
206228Because the split operation creates a new index to split the shards to,
207229the <<create-index-wait-for-active-shards,wait for active shards>> setting
208230on index creation applies to the split index action as well.
231+
232+
233+ [[split-index-api-path-params]]
234+ ==== {api-path-parms-title}
235+
236+ `<index>`::
237+ (Required, string)
238+ Name of the source index to split.
239+
240+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index]
241+
242+
243+ [[split-index-api-query-params]]
244+ ==== {api-query-parms-title}
245+
246+ include::{docdir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
247+
248+ include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
249+
250+
251+ [[split-index-api-request-body]]
252+ ==== {api-request-body-title}
253+
254+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-aliases]
255+
256+ include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-settings]
0 commit comments