---
type: api
title: Predict future behavior of a time series
description: Forecasts are not supported for jobs that perform population analysis; an
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-forecast
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-forecast
products:
  - Elasticsearch
---

# Predict future behavior of a time series

Availability: 6.1+

## Paths

- `POST` `/_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. The job must be open when you
create a forecast; otherwise, an error occurs.

## Description

Forecasts are not supported for jobs that perform population analysis; an
error occurs if you try to create a forecast for a job that has an
`over_field_name` in its configuration. Forcasts predict future behavior
based on historical data.

## Required authorization

* Cluster privileges: `manage_ml`

## Query String Parameters

- `duration` (string Duration · default: 1d)
  A period of time that indicates how far into the future to forecast. For
example, `30d` corresponds to 30 days. The forecast starts at the last
record that was processed.
- `expires_in` (string Duration · default: 14d)
  The period of time that forecast results are retained. After a forecast
expires, the results are deleted. If set to a value of 0, the forecast is
never automatically deleted.
- `max_model_memory` (string · default: 20mb)
  The maximum memory the forecast can use. If the forecast needs to use
more than the provided amount, it will spool to disk. Default is 20mb,
maximum is 500mb and minimum is 1mb. If set to 40% or more of the job’s
configured memory limit, it is automatically reduced to below that
amount.

## Request Body

`application/json`

- `duration` (string Duration · default: 1d) — optional
  Refer to the description for the `duration` query parameter.
- `expires_in` (string Duration · default: 14d) — optional
  Refer to the description for the `expires_in` query parameter.
- `max_model_memory` (string · default: 20mb) — optional
  Refer to the description for the `max_model_memory` query parameter.

## Response

`application/json`

- `acknowledged` (boolean)
- `forecast_id` (string Id)
## Code Examples

#### Console

```console
POST _ml/anomaly_detectors/low_request_rate/_forecast
{
  "duration": "10d"
}
```

#### JavaScript

```javascript
const response = await client.ml.forecast({
  job_id: "low_request_rate",
  duration: "10d",
});
```

#### Python

```python
resp = client.ml.forecast(
    job_id="low_request_rate",
    duration="10d",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/anomaly_detectors/low_request_rate/_forecast" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "duration": "10d"
  }'
```

#### Java

```java
client.ml().forecast(f -> f
    .duration(d -> d
        .time("10d")
    )
    .jobId("low_request_rate")
);
```

#### C#

```c#
var response = await client.MachineLearning
    .ForecastAsync(jobId: "low_request_rate", d1 => d1
        .Duration("10d")
    );
```

#### PHP

```php
$resp = $client->ml()->forecast([
    "job_id" => "low_request_rate",
    "body" => [
        "duration" => "10d",
    ],
]);
```

#### Ruby

```ruby
response = client.ml.forecast(
  job_id: "low_request_rate",
  body: {
    "duration": "10d"
  }
)
```

