2019-07-25 14:17:51 -04:00
|
|
|
[[indices-clone-index]]
|
2019-09-25 12:36:23 -04:00
|
|
|
=== Clone index API
|
|
|
|
++++
|
|
|
|
<titleabbrev>Clone index</titleabbrev>
|
|
|
|
++++
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
Clones an existing index.
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
2020-07-31 09:51:47 -04:00
|
|
|
POST /my-index-000001/_clone/cloned-my-index-000001
|
2019-09-25 12:36:23 -04:00
|
|
|
--------------------------------------------------
|
2020-07-31 09:51:47 -04:00
|
|
|
// TEST[s/^/PUT my-index-000001\n{"settings":{"index.number_of_shards" : 5,"blocks.write":true}}\n/]
|
2019-07-25 14:17:51 -04:00
|
|
|
|
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
[[clone-index-api-request]]
|
|
|
|
==== {api-request-title}
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
`POST /<index>/_clone/<target-index>`
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
`PUT /<index>/_clone/<target-index>`
|
2019-07-25 14:17:51 -04:00
|
|
|
|
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
[[clone-index-api-prereqs]]
|
|
|
|
==== {api-prereq-title}
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
To clone an index,
|
|
|
|
the index must be marked as read-only
|
|
|
|
and have a <<cluster-health,cluster health>> status of `green`.
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
For example,
|
|
|
|
the following request prevents write operations on `my_source_index`
|
|
|
|
so it can be cloned.
|
|
|
|
Metadata changes like deleting the index are still allowed.
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-07-25 14:17:51 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
PUT /my_source_index/_settings
|
|
|
|
{
|
|
|
|
"settings": {
|
2019-09-25 12:36:23 -04:00
|
|
|
"index.blocks.write": true
|
2019-07-25 14:17:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-25 12:36:23 -04:00
|
|
|
// TEST[s/^/PUT my_source_index\n/]
|
|
|
|
|
2020-06-22 08:29:26 -04:00
|
|
|
The current write index on a data stream cannot be cloned. In order to clone
|
|
|
|
the current write index, the data stream must first be
|
|
|
|
<<rollover-data-stream-ex,rolled over>> so that a new write index is created
|
|
|
|
and then the previous write index can be cloned.
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
[[clone-index-api-desc]]
|
|
|
|
==== {api-description-title}
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
Use the clone index API
|
|
|
|
to clone an existing index into a new index,
|
|
|
|
where each original primary shard is cloned
|
|
|
|
into a new primary shard in the new index.
|
|
|
|
|
|
|
|
[[cloning-works]]
|
|
|
|
===== How cloning works
|
|
|
|
|
|
|
|
Cloning works as follows:
|
|
|
|
|
|
|
|
* First, it creates a new target index with the same definition as the source
|
|
|
|
index.
|
|
|
|
|
|
|
|
* Then it hard-links segments from the source index into the target index. (If
|
|
|
|
the file system doesn't support hard-linking, then all segments are copied
|
|
|
|
into the new index, which is a much more time consuming process.)
|
|
|
|
|
|
|
|
* Finally, it recovers the target index as though it were a closed index which
|
|
|
|
had just been re-opened.
|
|
|
|
|
|
|
|
[[clone-index]]
|
|
|
|
===== Clone an index
|
2019-07-25 14:17:51 -04:00
|
|
|
|
|
|
|
To clone `my_source_index` into a new index called `my_target_index`, issue
|
|
|
|
the following request:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-07-25 14:17:51 -04:00
|
|
|
--------------------------------------------------
|
2019-09-25 12:36:23 -04:00
|
|
|
POST /my_source_index/_clone/my_target_index
|
2019-07-25 14:17:51 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
The above request returns immediately once the target index has been added to
|
|
|
|
the cluster state -- it doesn't wait for the clone operation to start.
|
|
|
|
|
|
|
|
[IMPORTANT]
|
|
|
|
=====================================
|
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
Indices can only be cloned if they meet the following requirements:
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
* The target index must not exist.
|
2019-07-25 14:17:51 -04:00
|
|
|
|
|
|
|
* The source index must have the same number of primary shards as the target index.
|
|
|
|
|
|
|
|
* The node handling the clone process must have sufficient free disk space to
|
|
|
|
accommodate a second copy of the existing index.
|
|
|
|
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
The `_clone` API is similar to the <<indices-create-index, `create index` API>>
|
|
|
|
and accepts `settings` and `aliases` parameters for the target index:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-07-25 14:17:51 -04:00
|
|
|
--------------------------------------------------
|
2019-09-25 12:36:23 -04:00
|
|
|
POST /my_source_index/_clone/my_target_index
|
2019-07-25 14:17:51 -04:00
|
|
|
{
|
|
|
|
"settings": {
|
|
|
|
"index.number_of_shards": 5 <1>
|
|
|
|
},
|
|
|
|
"aliases": {
|
|
|
|
"my_search_indices": {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "5"}}\n/]
|
|
|
|
|
|
|
|
<1> The number of shards in the target index. This must be equal to the
|
|
|
|
number of shards in the source index.
|
|
|
|
|
|
|
|
|
|
|
|
NOTE: Mappings may not be specified in the `_clone` request. The mappings of
|
|
|
|
the source index will be used for the target index.
|
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
[[monitor-cloning]]
|
|
|
|
===== Monitor the cloning process
|
2019-07-25 14:17:51 -04:00
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
The cloning process can be monitored with the <<cat-recovery,`_cat recovery`
|
2019-07-25 14:17:51 -04:00
|
|
|
API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
|
|
|
|
until all primary shards have been allocated by setting the `wait_for_status`
|
|
|
|
parameter to `yellow`.
|
|
|
|
|
|
|
|
The `_clone` API returns as soon as the target index has been added to the
|
|
|
|
cluster state, before any shards have been allocated. At this point, all
|
|
|
|
shards are in the state `unassigned`. If, for any reason, the target index
|
|
|
|
can't be allocated, its primary shard will remain `unassigned` until it
|
|
|
|
can be allocated on that node.
|
|
|
|
|
|
|
|
Once the primary shard is allocated, it moves to state `initializing`, and the
|
|
|
|
clone process begins. When the clone operation completes, the shard will
|
2019-09-25 12:36:23 -04:00
|
|
|
become `active`. At that point, {es} will try to allocate any
|
2019-07-25 14:17:51 -04:00
|
|
|
replicas and may decide to relocate the primary shard to another node.
|
|
|
|
|
2019-09-25 12:36:23 -04:00
|
|
|
[[clone-wait-active-shards]]
|
|
|
|
===== Wait for active shards
|
2019-07-25 14:17:51 -04:00
|
|
|
|
|
|
|
Because the clone operation creates a new index to clone the shards to,
|
|
|
|
the <<create-index-wait-for-active-shards,wait for active shards>> setting
|
|
|
|
on index creation applies to the clone index action as well.
|
2019-09-25 12:36:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[clone-index-api-path-params]]
|
|
|
|
==== {api-path-parms-title}
|
|
|
|
|
|
|
|
`<index>`::
|
|
|
|
(Required, string)
|
|
|
|
Name of the source index to clone.
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index]
|
2019-09-25 12:36:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[clone-index-api-query-params]]
|
|
|
|
==== {api-query-parms-title}
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=wait_for_active_shards]
|
2019-09-25 12:36:23 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
|
2019-09-25 12:36:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[clone-index-api-request-body]]
|
|
|
|
==== {api-request-body-title}
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index-aliases]
|
2019-09-25 12:36:23 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=target-index-settings]
|