---
type: api
title: Create a snapshot
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-snapshot-create
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-snapshot-create
products:
  - Elasticsearch
---

# Create a snapshot


Availability:

## Paths

- `POST` (also `PUT`) `/_snapshot/{repository}/{snapshot}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

#### Path Parameters

- `repository` (string Name)
  The name of the repository for the snapshot.
- `snapshot` (string Name)
  The name of the snapshot.
It supportes date math.
It must be unique in the repository.

## Description

Take a snapshot of a cluster or of data streams and indices.

## Required authorization

* Cluster privileges: `create_snapshot`

[More about managing snapshots](https://www.elastic.co/docs/deploy-manage/tools/snapshot-and-restore/create-snapshots)

## Query String Parameters

- `master_timeout` (string Duration · default: 30s)
  The 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.
- `wait_for_completion` (boolean · default: false)
  If `true`, the request returns a response when the snapshot is complete.
If `false`, the request returns a response when the snapshot initializes.

## Request Body

`application/json`

- `expand_wildcards` (string ExpandWildcards · default: all) — optional
  Determines how wildcard patterns in the `indices` parameter match data streams and indices.
It supports comma-separated values such as `open,hidden`.

Supported values include:
  - `all`: Match any data stream or index, including hidden ones.
  - `open`: Match open, non-hidden indices. Also matches any non-hidden data stream.
  - `closed`: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
  - `hidden`: Match hidden data streams and hidden indices. Must be combined with `open`, `closed`, or `both`.
  - `none`: Wildcard expressions are not accepted.
  Values: `all`, `open`, `closed`, `hidden`, `none`
- `feature_states` ([] string) — optional
  The feature states to include in the snapshot.
Each feature state includes one or more system indices containing related data.
You can view a list of eligible features using the get features API.

If `include_global_state` is `true`, all current feature states are included by default.
If `include_global_state` is `false`, no feature states are included by default.

Note that specifying an empty array will result in the default behavior.
To exclude all feature states, regardless of the `include_global_state` value, specify an array with only the value `none` (`["none"]`).
- `ignore_unavailable` (boolean · default: false) — optional
  If `true`, the request ignores data streams and indices in `indices` that are missing or closed.
If `false`, the request returns an error for any data stream or index that is missing or closed.
- `include_global_state` (boolean · default: true) — optional
  If `true`, the current cluster state is included in the snapshot.
The cluster state includes persistent cluster settings, composable index templates, legacy index templates, ingest pipelines, and ILM policies.
It also includes data stored in system indices, such as Watches and task records (configurable via `feature_states`).
- `indices` (string Indices) — optional
  A comma-separated list of data streams and indices to include in the snapshot.
It supports a multi-target syntax.
The default is an empty array (`[]`), which includes all regular data streams and regular indices.
To exclude all data streams and indices, use `-*`.

You can't use this parameter to include or exclude system indices or system data streams from a snapshot.
Use `feature_states` instead.
- `metadata` (Metadata) — optional
  Arbitrary metadata to the snapshot, such as a record of who took the snapshot, why it was taken, or any other useful data.
It can have any contents but it must be less than 1024 bytes.
This information is not automatically generated by Elasticsearch.
- `partial` (boolean · default: false) — optional
  If `true`, it enables you to restore 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.

If `false`, the entire restore operation will fail if one or more indices included in the snapshot do not have all primary shards available.

## Response

`application/json`

- `accepted` (boolean)
  Equals `true` if the snapshot was accepted. Present when the request had `wait_for_completion` set to `false`
- `snapshot` ({} SnapshotInfo)
  Snapshot information. Present when the request had `wait_for_completion` set to `true`
  - `data_streams` ([] string)
  - `duration` (string Duration)
  - `duration_in_millis` (DurationValueUnitMillis)
  - `end_time` (DateTime)
  - `end_time_in_millis` (EpochTimeUnitMillis)
  - `failures` ([] SnapshotShardFailure)
    - `index` (string IndexName)
    - `node_id` (string Id)
    - `reason` (string)
    - `shard_id` (number)
    - `index_uuid` (string Id)
    - `status` (string)
  - `include_global_state` (boolean)
  - `indices` ([] string IndexName)
  - `index_details` (map string to IndexDetails)
    Map values ({} IndexDetails)
    - `shard_count` (number)
    - `size` (number | string ByteSize)
    - `size_in_bytes` (number)
    - `max_segments_per_shard` (number)
  - `metadata` (Metadata)
  - `reason` (string)
  - `repository` (string Name)
  - `snapshot` (string Name)
  - `shards` ({} ShardStatistics)
    - `failed` (number uint)
      The number of shards the operation or search attempted to run on but failed.
    - `successful` (number uint)
      The number of shards the operation or search succeeded on.
    - `total` (number uint)
      The number of shards the operation or search will run on overall.
    - `failures` ([] ShardFailure)
      - `index` (string IndexName)
      - `node` (string)
      - `reason` ({} ErrorCause)
        - `type` (string)
          The type of error
        - `reason` (union string) — nullable
          A human-readable explanation of the error, in English.
          One of: `string`
        - `stack_trace` (string)
          The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
        - `caused_by` ({} ErrorCause) — recursive
          Same fields as `reason` in `failures`
        - `root_cause` ([] ErrorCause) — recursive
          Same fields as `reason` in `failures`
        - `suppressed` ([] ErrorCause) — recursive
          Same fields as `reason` in `failures`
      - `shard` (number)
      - `status` (string)
      - `primary` (boolean)
    - `skipped` (number uint)
  - `start_time` (DateTime)
  - `start_time_in_millis` (EpochTimeUnitMillis)
  - `state` (string)
  - `uuid` (string)
  - `version` (string)
  - `version_id` (number VersionNumber)
  - `feature_states` ([] InfoFeatureState)
    - `feature_name` (string)
    - `indices` (string Indices)
## Code Examples

#### Console

```console
POST /_snapshot/my_repository/snapshot_2?wait_for_completion=true
{
  "indices": "index_1,index_2",
  "ignore_unavailable": true,
  "include_global_state": false,
  "metadata": {
    "taken_by": "user123",
    "taken_because": "backup before upgrading"
  }
}
```

#### JavaScript

```javascript
const response = await client.snapshot.create({
  repository: "my_repository",
  snapshot: "snapshot_2",
  wait_for_completion: "true",
  indices: "index_1,index_2",
  ignore_unavailable: true,
  include_global_state: false,
  metadata: {
    taken_by: "user123",
    taken_because: "backup before upgrading",
  },
});
```

#### Python

```python
resp = client.snapshot.create(
    repository="my_repository",
    snapshot="snapshot_2",
    wait_for_completion=True,
    indices="index_1,index_2",
    ignore_unavailable=True,
    include_global_state=False,
    metadata={
        "taken_by": "user123",
        "taken_because": "backup before upgrading"
    },
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_snapshot/my_repository/snapshot_2?wait_for_completion=true" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "indices": "index_1,index_2",
    "ignore_unavailable": true,
    "include_global_state": false,
    "metadata": {
      "taken_by": "user123",
      "taken_because": "backup before upgrading"
    }
  }'
```

#### Java

```java
client.snapshot().create(c -> c
    .ignoreUnavailable(true)
    .includeGlobalState(false)
    .indices("index_1,index_2")
    .metadata(Map.of("taken_by", JsonData.fromJson("\"user123\""),"taken_because", JsonData.fromJson("\"backup before upgrading\"")))
    .partial(true)
    .repository("my_repository")
    .snapshot("snapshot_2")
    .waitForCompletion(true)
);
```

#### C#

```c#
var response = await client.Snapshot
    .CreateAsync(repository: "my_repository", snapshot: "snapshot_2", d1 => d1
        .WaitForCompletion(true)
        .IgnoreUnavailable(true)
        .IncludeGlobalState(false)
        .Indices(new[] { "index_1,index_2" })
        .Metadata(new Dictionary<string, object>()
        {
            { "taken_by", "user123" },
            { "taken_because", "backup before upgrading" }
        })
    );
```

#### PHP

```php
$resp = $client->snapshot()->create([
    "repository" => "my_repository",
    "snapshot" => "snapshot_2",
    "wait_for_completion" => "true",
    "body" => [
        "indices" => "index_1,index_2",
        "ignore_unavailable" => true,
        "include_global_state" => false,
        "metadata" => [
            "taken_by" => "user123",
            "taken_because" => "backup before upgrading",
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.snapshot.create(
  repository: "my_repository",
  snapshot: "snapshot_2",
  wait_for_completion: "true",
  body: {
    "indices": "index_1,index_2",
    "ignore_unavailable": true,
    "include_global_state": false,
    "metadata": {
      "taken_by": "user123",
      "taken_because": "backup before upgrading"
    }
  }
)
```

## Response Examples

#### Snapshot create response example1

A successful response from `PUT /_snapshot/my_repository/snapshot_2?wait_for_completion=true`.

```json
{
  "snapshot": {
    "snapshot": "snapshot_2",
    "uuid": "vdRctLCxSketdKb54xw67g",
    "repository": "my_repository",
    "version_id": <version_id>,
    "version": <version>,
    "indices": [],
    "data_streams": [],
    "feature_states": [],
    "include_global_state": false,
    "metadata": {
      "taken_by": "user123",
      "taken_because": "backup before upgrading"
    },
    "state": "SUCCESS",
    "start_time": "2020-06-25T14:00:28.850Z",
    "start_time_in_millis": 1593093628850,
    "end_time": "2020-06-25T14:00:28.850Z",
    "end_time_in_millis": 1593094752018,
    "duration_in_millis": 0,
    "failures": [],
    "shards": {
      "total": 0,
      "failed": 0,
      "successful": 0
    }
  }
}
```

