Restore snapshot API
editRestore snapshot API
editRestores a snapshot of a cluster or specified data streams and indices.
POST /_snapshot/my_repository/my_snapshot/_restore
Request
editPOST /_snapshot/<repository>/<snapshot>/_restore
Prerequisites
edit-
If the Elasticsearch security features are enabled, you must have the
manage
cluster privilege to use this API.
Description
editUse the restore snapshot API to restore a snapshot of a cluster, including all data streams and indices in the snapshot. If you do not want to restore the entire snapshot, you can select specific data streams or indices to restore.
You can run the restore operation on a cluster that contains an elected master node and has data nodes with enough capacity to accommodate the snapshot you are restoring. Existing indices can only be restored if they are closed and have the same number of shards as the indices in the snapshot. The restore operation automatically opens restored indices if they were closed and creates new indices if they do not exist in the cluster.
If a data stream is restored, its aliases and backing indices are also restored.
Alternatively, you can restore individual backing indices without restoring an
entire data stream. If you restore individual backing indices, they are not
automatically added to any existing data stream. For example, if only the
.ds-logs-2099.03.08-00003
backing index is restored from a snapshot, it is not
automatically added to the existing logs
data stream.
The index_settings
and ignore_index_settings
parameters affect
restored backing indices only. New backing indices created for a stream use the index
settings specified in the stream’s matching
index template.
If you change index settings during a restore, we recommend you make similar changes in the stream’s matching index template. This ensures new backing indices created for the stream use the same index settings.
Path parameters
edit-
<repository>
- (Required, string) Name of the repository to restore a snapshot from.
-
<snapshot>
- (Required, string) Name of the snapshot to restore.
Query parameters
edit-
master_timeout
-
(Optional, time units)
Period to wait for a connection to the master node. If no response is received
before the timeout expires, the request fails and returns an error. Defaults to
30s
. -
wait_for_completion
-
(Optional, Boolean) If
true
, the request returns a response when the restore operation completes. The operation is complete when it finishes all attempts to recover primary shards for restored indices. This applies even if one or more of the recovery attempts fail.If
false
, the request returns a response when the restore operation initializes. Defaults tofalse
.
Request body
edit-
ignore_unavailable
-
(Optional, Boolean) If
false
, the request returns an error for any data stream or index that is missing or closed. Defaults tofalse
.If
true
, the request ignores data streams and indices inindices
that are missing or closed. -
ignore_index_settings
- (Optional, string) A comma-separated list of index settings that should not be restored from a snapshot.
-
include_aliases
-
(Optional, Boolean)
If
true
, the request restores aliases for any restored data streams and indices. Iffalse
, the request doesn’t restore aliases. Defaults totrue
.
-
include_global_state
-
(Optional, Boolean) If
true
, restore the cluster state. Defaults tofalse
.The cluster state includes:
- Persistent cluster settings
- Index templates
- Legacy index templates
- Ingest pipelines
- ILM policies
- For snapshots taken after 7.12.0, data stored in system indices, such as Watches and task records.
If
include_global_state
istrue
then the restore operation merges the legacy index templates in your cluster with the templates contained in the snapshot, replacing any existing ones whose name matches one in the snapshot. It completely removes all persistent settings, non-legacy index templates, ingest pipelines and ILM lifecycle policies that exist in your cluster and replaces them with the corresponding items from the snapshot.You can use the
feature_states
parameter to configure how system indices are restored from the cluster state.
-
feature_states
-
(Optional, array of strings) A comma-separated list of feature states you wish to restore. Each feature state contains one or more system indices. The list of feature states available in a given snapshot are returned by the Get Snapshot API. Note that feature states restored this way will completely replace any existing configuration, rather than returning an error if the system index already exists. Providing an empty array will restore no feature states, regardless of the value of
include_global_state
.By default, all available feature states will be restored if
include_global_state
istrue
, and no feature states will be restored ifinclude_global_state
isfalse
.
-
index_settings
-
(Optional, string) A comma-separated list of settings to add or change in all restored indices. Use this parameter to override index settings when restoring snapshots.
For data streams, these index settings are applied to the restored backing indices.
For more information regarding all the different index-level settings that you can specify, see index modules.
-
indices
-
(Optional, string) A comma-separated list of data streams and indices to restore from the snapshot. Multi-index syntax is supported.
By default, a restore operation includes all data streams and indices in the snapshot. If this argument is provided, the restore operation only includes the specified data streams and indices.
-
partial
-
(Optional, Boolean) If
false
, the entire restore operation will fail if one or more indices included in the snapshot do not have all primary shards available. Defaults tofalse
.If
true
, allows restoring a partial snapshot of indices with unavailable shards. Only shards that were successfully included in the snapshot will be restored. All missing shards will be recreated as empty.
-
rename_pattern
-
(Optional, string) Defines a rename pattern to apply to restored data streams and indices. Data streams and indices matching the rename pattern will be renamed according to
rename_replacement
.The rename pattern is applied as defined by the regular expression that supports referencing the original text, according to the
appendReplacement
logic.The request will fail if two or more data streams or indices will be renamed into the same name.
If you rename a restored data stream, its backing indices are also renamed. For example, if you rename the
logs
data stream torestored-logs
, the backing index.ds-logs-2099.03.09-000005
is renamed to.ds-restored-logs-2099.03.09-000005
.
If you rename a restored stream, ensure an index template matches the new stream name. If no index template matches the stream, it cannot roll over or create new backing indices.
-
rename_replacement
-
(Optional, string)
Defines the rename replacement string. See
rename_pattern
for more information.
Examples
editThe following request restores index_1
and index_2
from snapshot_2
. The rename_pattern
and rename_replacement
parameters indicate any index matching the regular expression index_(.+)
will be renamed using the pattern restored_index_$1
when restored.
For example, index_1
will be renamed to restored_index_1
. index_2
will be renamed to restored_index_2
.
POST /_snapshot/my_repository/snapshot_2/_restore?wait_for_completion=true { "indices": "index_1,index_2", "ignore_unavailable": true, "include_global_state": false, "rename_pattern": "index_(.+)", "rename_replacement": "restored_index_$1", "include_aliases": false }
The API returns an acknowledgement if the request succeeds. If the request encounters errors, the response indicates any issues found, such as open indices that are blocking the restore operation from completing.