---
type: api
title: Revert to a snapshot
description: The machine learning features react quickly to anomalous input, learning new
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-ml-revert-model-snapshot
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-ml-revert-model-snapshot
products:
  - Elasticsearch
---

# Revert to a snapshot

Availability: Generally available since 5.4

## Paths

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

#### Path parameters

- `job_id` (string) — required
  Identifier for the anomaly detection job.
- `snapshot_id` (string) — required
  You can specify `empty` as the <snapshot_id>. Reverting to the empty
snapshot means the anomaly detection job starts learning a new model from
scratch when it is started.

## Description

The machine learning features react quickly to anomalous input, learning new
behaviors in data. Highly anomalous input increases the variance in the
models whilst the system learns whether this is a new step-change in behavior
or a one-off event. In the case where this anomalous input is known to be a
one-off, then it might be appropriate to reset the model state to a time
before this event. For example, you might consider reverting to a saved
snapshot after Black Friday or a critical system failure.

## 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

- `delete_intervening_results` (boolean · default: false) — optional
  If true, deletes the results in the time period between the latest
results and the time of the reverted snapshot. It also resets the model
to accept records for this time period. If you choose not to delete
intervening results when reverting a snapshot, the job will not accept
input data that is older than the current time. If you want to resend
data, then delete the intervening results.

## Request body

`application/json`

- `delete_intervening_results` (boolean · default: false) — optional
  Refer to the description for the `delete_intervening_results` query parameter.

## Response

`application/json`

- `model` (object)
  - `description` (string)
    An optional description of the job.
  - `job_id` (string)
    A numerical character string that uniquely identifies the job that the snapshot was created for.
  - `latest_record_time_stamp` (number)
    The timestamp of the latest processed record.
  - `latest_result_time_stamp` (number)
    The timestamp of the latest bucket result.
  - `min_version` (string)
    The minimum version required to be able to restore the model snapshot.
  - `model_size_stats` (object)
    Summary information describing the model.
    - `bucket_allocation_failures_count` (number)
    - `job_id` (string)
    - `log_time` (union)
    - `memory_status` (enum)
      Values: `ok`, `soft_limit`, `hard_limit`
    - `model_bytes` (number | string)
    - `model_bytes_exceeded` (number | string)
    - `model_bytes_memory_limit` (number | string)
    - `output_memory_allocator_bytes` (number | string)
    - `peak_model_bytes` (number | string)
    - `assignment_memory_basis` (string)
    - `result_type` (string)
    - `total_by_field_count` (number)
    - `total_over_field_count` (number)
    - `total_partition_field_count` (number)
    - `categorization_status` (enum)
      Values: `ok`, `warn`
    - `categorized_doc_count` (number)
    - `dead_category_count` (number)
    - `failed_category_count` (number)
    - `frequent_category_count` (number)
    - `rare_category_count` (number)
    - `total_category_count` (number)
    - `timestamp` (number)
  - `retain` (boolean)
    If true, this snapshot will not be deleted during automatic cleanup of snapshots older than model_snapshot_retention_days. However, this snapshot will be deleted when the job is deleted. The default value is false.
  - `snapshot_doc_count` (number)
    For internal use only.
  - `snapshot_id` (string)
    A numerical character string that uniquely identifies the model snapshot.
  - `timestamp` (number)
    The creation timestamp for the snapshot.
## Code examples

#### Console

```console
POST _ml/anomaly_detectors/low_request_rate/model_snapshots/1637092688/_revert
{
  "delete_intervening_results": true
}
```

#### JavaScript

```javascript
const response = await client.ml.revertModelSnapshot({
  job_id: "low_request_rate",
  snapshot_id: 1637092688,
  delete_intervening_results: true,
});
```

#### Python

```python
resp = client.ml.revert_model_snapshot(
    job_id="low_request_rate",
    snapshot_id="1637092688",
    delete_intervening_results=True,
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/anomaly_detectors/low_request_rate/model_snapshots/1637092688/_revert" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "delete_intervening_results": true
  }'
```

#### Java

```java
client.ml().revertModelSnapshot(r -> r
    .deleteInterveningResults(true)
    .jobId("low_request_rate")
    .snapshotId("1637092688")
);
```

#### C#

```c#
var response = await client.MachineLearning
    .RevertModelSnapshotAsync(jobId: "low_request_rate", snapshotId: "1637092688", d1 => d1
        .DeleteInterveningResults(true)
    );
```

#### PHP

```php
$resp = $client->ml()->revertModelSnapshot([
    "job_id" => "low_request_rate",
    "snapshot_id" => "1637092688",
    "body" => [
        "delete_intervening_results" => true,
    ],
]);
```

#### Ruby

```ruby
response = client.ml.revert_model_snapshot(
  job_id: "low_request_rate",
  snapshot_id: "1637092688",
  body: {
    "delete_intervening_results": true
  }
)
```

