---
type: api
title: Delete forecasts from a job
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-delete-forecast
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-delete-forecast
products:
  - Elasticsearch
---

# Delete forecasts from a job


Availability: 6.5+

## Paths

- `DELETE` `/_ml/anomaly_detectors/{job_id}/_forecast/{forecast_id}`
- `DELETE` `/_ml/anomaly_detectors/{job_id}/_forecast`

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

- `job_id` (string Id)
  Identifier for the anomaly detection job.
- `forecast_id` (string Id) — optional, leave it out to use `/_ml/anomaly_detectors/{job_id}/_forecast`
  A comma-separated list of forecast identifiers. If you do not specify
this optional parameter or if you specify `_all` or `*` the API deletes
all forecasts from the job.

## Description

By default, forecasts are retained for 14 days. You can specify a
different retention period with the `expires_in` parameter in the forecast
jobs API. The delete forecast API enables you to delete one or more
forecasts before they expire.

## Required authorization

* Cluster privileges: `manage_ml`

## Query String Parameters

- `allow_no_forecasts` (boolean · default: true)
  Specifies whether an error occurs when there are no forecasts. In
particular, if this parameter is set to `false` and there are no
forecasts associated with the job, attempts to delete all forecasts
return an error.
- `timeout` (string Duration · default: 30s)
  Specifies the period of time to wait for the completion of the delete
operation. When this period of time elapses, the API fails and returns an
error.

## Response

`application/json`

- `acknowledged` (boolean)
  For a successful response, this value is always true. On failure, an exception is returned instead.
## Code Examples

#### Console

```console
DELETE _ml/anomaly_detectors/total-requests/_forecast/_all
```

#### JavaScript

```javascript
const response = await client.ml.deleteForecast({
  job_id: "total-requests",
  forecast_id: "_all",
});
```

#### Python

```python
resp = client.ml.delete_forecast(
    job_id="total-requests",
    forecast_id="_all",
)
```

#### curl

```curl
curl -X DELETE "$ELASTICSEARCH_URL/_ml/anomaly_detectors/total-requests/_forecast/_all" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().deleteForecast(d -> d
    .forecastId("_all")
    .jobId("total-requests")
);
```

#### C#

```c#
var response = await client.MachineLearning
    .DeleteForecastAsync(new DeleteForecastRequest()
    {
        ForecastId = "_all",
        JobId = "total-requests"
    });
```

#### PHP

```php
$resp = $client->ml()->deleteForecast([
    "job_id" => "total-requests",
    "forecast_id" => "_all",
]);
```

#### Ruby

```ruby
response = client.ml.delete_forecast(
  job_id: "total-requests",
  forecast_id: "_all"
)
```

## Response Examples

#### Ml delete forecast response example1

A successful response when deleting a forecast from an anomaly detection job.

```json
{
  "acknowledged": true
}
```

