---
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/4641/api/doc/elasticsearch/v9/operation/operation-ml-upgrade-job-snapshot
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/v9/operation/operation-ml-upgrade-job-snapshot
products:
  - Elasticsearch
---

# Upgrade a snapshot

Authentication: required

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`

## 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
        .time("45m")
    )
    .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"
)
```

## Response examples

#### 200

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "node": "string",
  "completed": false
}
```

