---
type: api
title: Upgrade a snapshot
description: Upgrade an anomaly detection model snapshot to the latest major version.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-ml-upgrade-job-snapshot
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-ml-upgrade-job-snapshot
products:
  - Elasticsearch
---

# Upgrade a snapshot

Availability: Generally available since 5.4

## Paths

- `POST` `/_ml/anomaly_detectors/{job_id}/model_snapshots/{snapshot_id}/_upgrade`

#### Path parameters

- `job_id` (string) — required
  Identifier for the anomaly detection job.
- `snapshot_id` (string) — required
  A numerical character string that uniquely identifies the model snapshot.

## Description

Upgrade an anomaly detection model snapshot to the latest major version.
Over time, older snapshot formats are deprecated and removed. Anomaly
detection jobs support only snapshots that are from the current or previous
major version.
This API provides a means to upgrade a snapshot to the current major version.
This aids in preparing the cluster for an upgrade to the next major version.
Only one snapshot per anomaly detection job can be upgraded at a time and the
upgraded snapshot cannot be the current snapshot of the anomaly detection
job.

## Required authorization

- Cluster privileges: `manage_ml`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/guide/en/elasticsearch/reference/current/token-authentication-services.html)

## Query string parameters

- `wait_for_completion` (boolean · default: false) — optional
  When true, the API won’t respond until the upgrade is complete.
Otherwise, it responds as soon as the upgrade task is assigned to a node.
- `timeout` (string · default: 30m) — optional
  Controls the time to wait for the request to complete.

## Response

`application/json`

- `node` (string)
  The ID of the node that the upgrade task was started on if it is still running. In serverless this will be the "serverless".
- `completed` (boolean)
  When true, this means the task is complete. When false, it is still running.
## Code examples

#### Console

```console
POST _ml/anomaly_detectors/low_request_rate/model_snapshots/1828371/_upgrade?timeout=45m&wait_for_completion=true
```

#### JavaScript

```javascript
const response = await client.ml.upgradeJobSnapshot({
  job_id: "low_request_rate",
  snapshot_id: 1828371,
  timeout: "45m",
  wait_for_completion: "true",
});
```

#### Python

```python
resp = client.ml.upgrade_job_snapshot(
    job_id="low_request_rate",
    snapshot_id="1828371",
    timeout="45m",
    wait_for_completion=True,
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/anomaly_detectors/low_request_rate/model_snapshots/1828371/_upgrade?timeout=45m&wait_for_completion=true" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().upgradeJobSnapshot(u -> u
    .jobId("low_request_rate")
    .snapshotId("1828371")
    .timeout(t -> t
        .offset(45)
    )
    .waitForCompletion(true)
);
```

#### C#

```c#
var response = await client.MachineLearning
    .UpgradeJobSnapshotAsync(jobId: "low_request_rate", snapshotId: "1828371", d1 => d1
        .Timeout("45m")
        .WaitForCompletion(true)
    );
```

#### PHP

```php
$resp = $client->ml()->upgradeJobSnapshot([
    "job_id" => "low_request_rate",
    "snapshot_id" => "1828371",
    "timeout" => "45m",
    "wait_for_completion" => "true",
]);
```

#### Ruby

```ruby
response = client.ml.upgrade_job_snapshot(
  job_id: "low_request_rate",
  snapshot_id: "1828371",
  timeout: "45m",
  wait_for_completion: "true"
)
```

