Skip to content

Commit 29c1424

Browse files
authored
[DOCS] Reformat shrink index API docs (#46711) (#47587)
1 parent cc0502f commit 29c1424

File tree

1 file changed

+91
-39
lines changed

1 file changed

+91
-39
lines changed

docs/reference/indices/shrink-index.asciidoc

Lines changed: 91 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,36 @@
44
<titleabbrev>Shrink index</titleabbrev>
55
++++
66

7-
The shrink index API allows you to shrink an existing index into a new index
8-
with fewer primary shards. The requested number of primary shards in the target index
9-
must be a factor of the number of shards in the source index. For example an index with
10-
`8` primary shards can be shrunk into `4`, `2` or `1` primary shards or an index
11-
with `15` primary shards can be shrunk into `5`, `3` or `1`. If the number
12-
of shards in the index is a prime number it can only be shrunk into a single
13-
primary shard. Before shrinking, a (primary or replica) copy of every shard
14-
in the index must be present on the same node.
7+
Shrinks an existing index into a new index with fewer primary shards.
158

16-
Shrinking works as follows:
179

18-
* First, it creates a new target index with the same definition as the source
19-
index, but with a smaller number of primary shards.
10+
[source,console]
11+
----
12+
POST /twitter/_shrink/shrunk-twitter-index
13+
----
14+
// TEST[s/^/PUT twitter\n{"settings":{"index.number_of_shards":2,"blocks.write":true}}\n/]
2015

21-
* Then it hard-links segments from the source index into the target index. (If
22-
the file system doesn't support hard-linking, then all segments are copied
23-
into the new index, which is a much more time consuming process. Also if using
24-
multiple data paths, shards on different data paths require a full copy of
25-
segment files if they are not on the same disk since hardlinks don’t work across
26-
disks)
2716

28-
* Finally, it recovers the target index as though it were a closed index which
29-
had just been re-opened.
17+
[[shrink-index-api-request]]
18+
==== {api-request-title}
19+
20+
`POST /<index>/_shrink/<target-index>`
21+
22+
`PUT /<index>/_shrink/<target-index>`
23+
3024

31-
[float]
32-
==== Preparing an index for shrinking
25+
[[shrink-index-api-prereqs]]
26+
==== {api-prereq-title}
3327

34-
In order to shrink an index, the index must be marked as read-only, and a
35-
(primary or replica) copy of every shard in the index must be relocated to the
36-
same node and have <<cluster-health,health>> `green`.
28+
Before you can shrink an index:
3729

38-
These two conditions can be achieved with the following request:
30+
* The index must be read-only.
31+
* A copy of every shard in the index must reside on the same node.
32+
* The <<cluster-health, cluster health>> status must be green.
3933

40-
[source,js]
34+
These three conditions can be achieved with the following request:
35+
36+
[source,console]
4137
--------------------------------------------------
4238
PUT /my_source_index/_settings
4339
{
@@ -47,7 +43,6 @@ PUT /my_source_index/_settings
4743
}
4844
}
4945
--------------------------------------------------
50-
// CONSOLE
5146
// TEST[s/^/PUT my_source_index\n{"settings":{"index.number_of_shards":2}}\n/]
5247
<1> Forces the relocation of a copy of each shard to the node with name
5348
`shrink_node_name`. See <<shard-allocation-filtering>> for more options.
@@ -60,23 +55,54 @@ with the <<cat-recovery,`_cat recovery` API>>, or the <<cluster-health,
6055
`cluster health` API>> can be used to wait until all shards have relocated
6156
with the `wait_for_no_relocating_shards` parameter.
6257

63-
[float]
64-
==== Shrinking an index
58+
59+
[[shrink-index-api-desc]]
60+
==== {api-description-title}
61+
62+
The shrink index API allows you to shrink an existing index into a new index
63+
with fewer primary shards. The requested number of primary shards in the target index
64+
must be a factor of the number of shards in the source index. For example an index with
65+
`8` primary shards can be shrunk into `4`, `2` or `1` primary shards or an index
66+
with `15` primary shards can be shrunk into `5`, `3` or `1`. If the number
67+
of shards in the index is a prime number it can only be shrunk into a single
68+
primary shard. Before shrinking, a (primary or replica) copy of every shard
69+
in the index must be present on the same node.
70+
71+
[[how-shrink-works]]
72+
===== How shrinking works
73+
74+
A shrink operation:
75+
76+
. Creates a new target index with the same definition as the source
77+
index, but with a smaller number of primary shards.
78+
79+
. Hard-links segments from the source index into the target index. (If
80+
the file system doesn't support hard-linking, then all segments are copied
81+
into the new index, which is a much more time consuming process. Also if using
82+
multiple data paths, shards on different data paths require a full copy of
83+
segment files if they are not on the same disk since hardlinks don’t work across
84+
disks)
85+
86+
. Recovers the target index as though it were a closed index which
87+
had just been re-opened.
88+
89+
90+
[[_shrinking_an_index]]
91+
===== Shrink an index
6592

6693
To shrink `my_source_index` into a new index called `my_target_index`, issue
6794
the following request:
6895

69-
[source,js]
96+
[source,console]
7097
--------------------------------------------------
71-
POST my_source_index/_shrink/my_target_index
98+
POST /my_source_index/_shrink/my_target_index
7299
{
73100
"settings": {
74101
"index.routing.allocation.require._name": null, <1>
75102
"index.blocks.write": null <2>
76103
}
77104
}
78105
--------------------------------------------------
79-
// CONSOLE
80106
// TEST[continued]
81107

82108
<1> Clear the allocation requirement copied from the source index.
@@ -110,9 +136,9 @@ Indices can only be shrunk if they satisfy the following requirements:
110136
The `_shrink` API is similar to the <<indices-create-index, `create index` API>>
111137
and accepts `settings` and `aliases` parameters for the target index:
112138

113-
[source,js]
139+
[source,console]
114140
--------------------------------------------------
115-
POST my_source_index/_shrink/my_target_index
141+
POST /my_source_index/_shrink/my_target_index
116142
{
117143
"settings": {
118144
"index.number_of_replicas": 1,
@@ -124,7 +150,6 @@ POST my_source_index/_shrink/my_target_index
124150
}
125151
}
126152
--------------------------------------------------
127-
// CONSOLE
128153
// TEST[s/^/PUT my_source_index\n{"settings": {"index.number_of_shards":5,"index.blocks.write": true}}\n/]
129154

130155
<1> The number of shards in the target index. This must be a factor of the
@@ -136,8 +161,9 @@ POST my_source_index/_shrink/my_target_index
136161

137162
NOTE: Mappings may not be specified in the `_shrink` request.
138163

139-
[float]
140-
==== Monitoring the shrink process
164+
165+
[[monitor-shrink]]
166+
===== Monitor the shrink process
141167

142168
The shrink process can be monitored with the <<cat-recovery,`_cat recovery`
143169
API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
@@ -155,9 +181,35 @@ shrink process begins. When the shrink operation completes, the shard will
155181
become `active`. At that point, Elasticsearch will try to allocate any
156182
replicas and may decide to relocate the primary shard to another node.
157183

158-
[float]
159-
==== Wait For Active Shards
184+
185+
[[shrink-wait-active-shards]]
186+
===== Wait for active shards
160187

161188
Because the shrink operation creates a new index to shrink the shards to,
162189
the <<create-index-wait-for-active-shards,wait for active shards>> setting
163190
on index creation applies to the shrink index action as well.
191+
192+
193+
[[shrink-index-api-path-params]]
194+
==== {api-path-parms-title}
195+
196+
`<index>`::
197+
(Required, string)
198+
Name of the source index to shrink.
199+
200+
include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index]
201+
202+
[[shrink-index-api-query-params]]
203+
==== {api-query-parms-title}
204+
205+
include::{docdir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
206+
207+
include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
208+
209+
210+
[[shrink-index-api-request-body]]
211+
==== {api-request-body-title}
212+
213+
include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-aliases]
214+
215+
include::{docdir}/rest-api/common-parms.asciidoc[tag=target-index-settings]

0 commit comments

Comments
 (0)