---
type: api
title: Get anomaly detection job stats
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-ml-get-job-stats
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-ml-get-job-stats
products:
  - Elasticsearch
---

# Get anomaly detection job stats


Availability: Generally available since 5.5

## Paths

- `GET` `/_ml/anomaly_detectors/{job_id}/_stats`
- `GET` `/_ml/anomaly_detectors/_stats`

#### Path parameters

- `job_id` (string) — optional, leave it out to use `/_ml/anomaly_detectors/_stats`
  Identifier for the anomaly detection job. It can be a job identifier, a
group name, a comma-separated list of jobs, or a wildcard expression. If
you do not specify one of these options, the API returns information for
all anomaly detection jobs.

## Required authorization

- Cluster privileges: `monitor_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

- `allow_no_match` (boolean · default: true) — optional
  Specifies what to do when the request:

1. Contains wildcard expressions and there are no jobs that match.
2. Contains the _all string or no identifiers and there are no matches.
3. Contains wildcard expressions and there are only partial matches.

If `true`, the API returns an empty `jobs` array when
there are no matches and the subset of results when there are partial
matches. If `false`, the API returns a `404` status
code when there are no matches or only partial matches.

## Response

`application/json`

- `count` (number)
- `jobs` (object[])
  - `assignment_explanation` (string)
    For open anomaly detection jobs only, contains messages relating to the selection of a node to run the job.
  - `data_counts` (object)
    An object that describes the quantity of input to the job and any related error counts.
The `data_count` values are cumulative for the lifetime of a job.
If a model snapshot is reverted or old results are deleted, the job counts are not reset.
    - `bucket_count` (number)
    - `earliest_record_timestamp` (number)
    - `empty_bucket_count` (number)
    - `input_bytes` (number)
    - `input_field_count` (number)
    - `input_record_count` (number)
    - `invalid_date_count` (number)
    - `job_id` (string)
    - `last_data_time` (number)
    - `latest_empty_bucket_timestamp` (number)
    - `latest_record_timestamp` (number)
    - `latest_sparse_bucket_timestamp` (number)
    - `latest_bucket_timestamp` (number)
    - `log_time` (number)
    - `missing_field_count` (number)
    - `out_of_order_timestamp_count` (number)
    - `processed_field_count` (number)
    - `processed_record_count` (number)
    - `sparse_bucket_count` (number)
  - `forecasts_stats` (object)
    An object that provides statistical information about forecasts belonging to this job.
Some statistics are omitted if no forecasts have been made.
    - `memory_bytes` (object)
      - `avg` (number)
      - `max` (number)
      - `min` (number)
      - `total` (number)
    - `processing_time_ms` (object)
      - `avg` (number)
      - `max` (number)
      - `min` (number)
      - `total` (number)
    - `records` (object)
      - `avg` (number)
      - `max` (number)
      - `min` (number)
      - `total` (number)
    - `status` (map string to number)
    - `total` (number)
    - `forecasted_jobs` (number)
  - `job_id` (string)
    Identifier for the anomaly detection job.
  - `model_size_stats` (object)
    An object that provides information about the size and contents of 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)
  - `node` (object)
    Contains properties for the node that runs the job.
This information is available only for open jobs.
    - `name` (string)
    - `ephemeral_id` (string)
    - `id` (string)
    - `transport_address` (string)
    - `attributes` (map string to string)
  - `open_time` (union)
    For open jobs only, the elapsed time for which the job has been open.
  - `state` (enum)
    The status of the anomaly detection job, which can be one of the following values: `closed`, `closing`, `failed`, `opened`, `opening`.

Supported values include:
  - `closing`: The job close action is in progress and has not yet completed. A closing job cannot accept further data.
  - `closed`: The job finished successfully with its model state persisted. The job must be opened before it can accept further data.
  - `opened`: The job is available to receive and process data.
  - `failed`: The job did not finish successfully due to an error.
This situation can occur due to invalid input data, a fatal error occurring during the analysis, or an external interaction such as the process being killed by the Linux out of memory (OOM) killer.
If the job had irrevocably failed, it must be force closed and then deleted.
If the datafeed can be corrected, the job can be closed and then re-opened.
  - `opening`: The job open action is in progress and has not yet completed.
    Values: `closing`, `closed`, `opened`, `failed`, `opening`
  - `timing_stats` (object)
    An object that provides statistical information about timing aspect of this job.
    - `average_bucket_processing_time_ms` (number)
    - `bucket_count` (number)
    - `exponential_average_bucket_processing_time_ms` (number)
    - `exponential_average_bucket_processing_time_per_hour_ms` (number)
    - `job_id` (string)
    - `total_bucket_processing_time_ms` (number)
    - `maximum_bucket_processing_time_ms` (number)
    - `minimum_bucket_processing_time_ms` (number)
  - `deleting` (boolean)
    Indicates that the process of deleting the job is in progress but not yet completed. It is only reported when `true`.
## Code examples

#### Console

```console
GET _ml/anomaly_detectors/low_request_rate/_stats
```

#### JavaScript

```javascript
const response = await client.ml.getJobStats({
  job_id: "low_request_rate",
});
```

#### Python

```python
resp = client.ml.get_job_stats(
    job_id="low_request_rate",
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_ml/anomaly_detectors/low_request_rate/_stats" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().getJobStats(g -> g
    .jobId("low_request_rate")
);
```

#### C#

```c#
var response = await client.MachineLearning
    .GetJobStatsAsync(d1 => d1
        .JobId("low_request_rate")
    );
```

#### PHP

```php
$resp = $client->ml()->getJobStats([
    "job_id" => "low_request_rate",
]);
```

#### Ruby

```ruby
response = client.ml.get_job_stats(
  job_id: "low_request_rate"
)
```

