Skip to content

Commit 4837059

Browse files
committed
[DOCS] Reformat clone index API docs (#46762)
1 parent 5d70750 commit 4837059

File tree

2 files changed

+117
-56
lines changed

2 files changed

+117
-56
lines changed
Lines changed: 89 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,83 @@
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
--------------------------------------------------
4638
PUT /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

6274
To clone `my_source_index` into a new index called `my_target_index`, issue
6375
the 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

7283
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.
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:
89100
The `_clone` API is similar to the <<indices-create-index, `create index` API>>
90101
and 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
111121
NOTE: Mappings may not be specified in the `_clone` request. The mappings of
112122
the 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`
118128
API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
119129
until all primary shards have been allocated by setting the `wait_for_status`
120130
parameter to `yellow`.
@@ -127,12 +137,38 @@ can be allocated on that node.
127137

128138
Once the primary shard is allocated, it moves to state `initializing`, and the
129139
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
131141
replicas 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

136146
Because the clone operation creates a new index to clone the shards to,
137147
the <<create-index-wait-for-active-shards,wait for active shards>> setting
138148
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]

docs/reference/rest-api/common-parms.asciidoc

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ If specified,
1818
the index alias only applies to documents returned by the filter.
1919
end::index-alias-filter[]
2020

21+
tag::target-index-aliases[]
22+
`aliases`::
23+
(Optional, <<indices-aliases,alias object>>)
24+
Index aliases which include the target index.
25+
See <<indices-aliases>>.
26+
end::target-index-aliases[]
27+
2128
tag::allow-no-indices[]
2229
`allow_no_indices`::
2330
(Optional, boolean) If `true`,
@@ -489,15 +496,22 @@ the segment has most likely been written to disk
489496
but needs a <<indices-refresh,refresh>> to be searchable.
490497
end::segment-search[]
491498

499+
tag::segment-size[]
500+
Disk space used by the segment, such as `50kb`.
501+
end::segment-size[]
502+
492503
tag::settings[]
493504
`settings`::
494505
(Optional, <<index-modules-settings,index setting object>>) Configuration
495506
options for the index. See <<index-modules-settings>>.
496507
end::settings[]
497508

498-
tag::segment-size[]
499-
Disk space used by the segment, such as `50kb`.
500-
end::segment-size[]
509+
tag::target-index-settings[]
510+
`settings`::
511+
(Optional, <<index-modules-settings,index setting object>>)
512+
Configuration options for the target index.
513+
See <<index-modules-settings>>.
514+
end::target-index-settings[]
501515

502516
tag::slices[]
503517
`slices`::
@@ -534,6 +548,17 @@ tag::stats[]
534548
purposes.
535549
end::stats[]
536550

551+
tag::target-index[]
552+
`<target-index>`::
553+
+
554+
--
555+
(Required, string)
556+
Name of the target index to create.
557+
558+
include::{docdir}/indices/create-index.asciidoc[tag=index-name-reqs]
559+
--
560+
end::target-index[]
561+
537562
tag::terminate_after[]
538563
`terminate_after`::
539564
(Optional, integer) The maximum number of documents to collect for each shard,

0 commit comments

Comments
 (0)