---
type: api
title: Delete expired ML data
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-ml-delete-expired-data
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-ml-delete-expired-data
products:
  - Elasticsearch
---

# Delete expired ML data


Availability: 5.4+

## Paths

- `DELETE` `/_ml/_delete_expired_data/{job_id}`
- `DELETE` `/_ml/_delete_expired_data`

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

#### Path Parameters

- `job_id` (string Id) — optional, leave it out to use `/_ml/_delete_expired_data`
  Identifier for an anomaly detection job. It can be a job identifier, a
group name, or a wildcard expression.

## Description

Delete all job results, model snapshots and forecast data that have exceeded
their retention days period. Machine learning state documents that are not
associated with any job are also deleted.
You can limit the request to a single or set of anomaly detection jobs by
using a job identifier, a group name, a comma-separated list of jobs, or a
wildcard expression. You can delete expired data for all anomaly detection
jobs by using `_all`, by specifying `*` as the `<job_id>`, or by omitting the
`<job_id>`.

## Required authorization

* Cluster privileges: `manage_ml`

## Query String Parameters

- `requests_per_second` (number)
  The desired requests per second for the deletion processes. The default
behavior is no throttling.
- `timeout` (string Duration · default: 8h)
  How long can the underlying delete processes run until they are canceled.

## Request Body

`application/json`

- `requests_per_second` (number) — optional
  The desired requests per second for the deletion processes. The default
behavior is no throttling.
- `timeout` (string Duration · default: 8h) — optional
  How long can the underlying delete processes run until they are canceled.

## Response

`application/json`

- `deleted` (boolean)
## Code Examples

#### Console

```console
DELETE _ml/_delete_expired_data?timeout=1h
```

#### JavaScript

```javascript
const response = await client.ml.deleteExpiredData({
  timeout: "1h",
});
```

#### Python

```python
resp = client.ml.delete_expired_data(
    timeout="1h",
)
```

#### curl

```curl
curl -X DELETE "$ELASTICSEARCH_URL/_ml/_delete_expired_data?timeout=1h" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().deleteExpiredData(d -> d
    .timeout(t -> t
        .time("1h")
    )
);
```

#### C#

```c#
var response = await client.MachineLearning.DeleteExpiredDataAsync();
```

#### PHP

```php
$resp = $client->ml()->deleteExpiredData([
    "timeout" => "1h",
]);
```

#### Ruby

```ruby
response = client.ml.delete_expired_data(
  timeout: "1h"
)
```

## Response Examples

#### Ml delete expired data response example1

A successful response when deleting expired and unused anomaly detection data.

```json
{
  "deleted": true
}
```

