---
type: api
title: Open anomaly detection jobs
description: An anomaly detection job must be opened to be ready to receive and analyze
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-ml-open-job
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-ml-open-job
products:
  - Elasticsearch
---

# Open anomaly detection jobs

Availability: Generally available since 5.4

## Paths

- `POST` `/_ml/anomaly_detectors/{job_id}/_open`

#### Path parameters

- `job_id` (string) — required
  Identifier for the anomaly detection job.

## Description

An anomaly detection job must be opened to be ready to receive and analyze
data. It can be opened and closed multiple times throughout its lifecycle.
When you open a new job, it starts with an empty model.
When you open an existing job, the most recent model state is automatically
loaded. The job is ready to resume its analysis from where it left off, once
new data is received.

## 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/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Query string parameters

- `timeout` (string · default: 30m) — optional
  Controls the time to wait until a job has opened.

## Request body

`application/json`

- `timeout` (string · default: 30m) — optional
  Refer to the description for the `timeout` query parameter.

## Response

`application/json`

- `opened` (boolean)
- `node` (string)
  The ID of the node that the job was started on. In serverless this will be the "serverless".
If the job is allowed to open lazily and has not yet been assigned to a node, this value is an empty string.
## Code examples

#### Console

```console
POST /_ml/anomaly_detectors/job-01/_open
{
  "timeout": "35m"
}
```

#### JavaScript

```javascript
const response = await client.ml.openJob({
  job_id: "job-01",
  timeout: "35m",
});
```

#### Python

```python
resp = client.ml.open_job(
    job_id="job-01",
    timeout="35m",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/anomaly_detectors/job-01/_open" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "timeout": "35m"
  }'
```

#### Java

```java
client.ml().openJob(o -> o
    .jobId("job-01")
    .timeout(t -> t
        .time("35m")
    )
);
```

#### C#

```c#
var response = await client.MachineLearning
    .OpenJobAsync(jobId: "job-01", d1 => d1
        .Timeout("35m")
    );
```

#### PHP

```php
$resp = $client->ml()->openJob([
    "job_id" => "job-01",
    "body" => [
        "timeout" => "35m",
    ],
]);
```

#### Ruby

```ruby
response = client.ml.open_job(
  job_id: "job-01",
  body: {
    "timeout": "35m"
  }
)
```

## Response examples

#### Ml open job response example1

A successful response when opening an anomaly detection job.

```json
{
  "opened": true,
  "node": "node-1"
}
```

