---
type: api
title: "Query Prometheus exemplars"
description: "Get the exemplars of the series selected by a PromQL expression over a time range."
url: https://www.elastic.co/elastic/docs-builder/docs/5103/api/elasticsearch-serverless/operation/operation-prometheus-query-exemplars
resource: https://www.elastic.co/elastic/docs-builder/docs/5103/api/elasticsearch-serverless/operation/operation-prometheus-query-exemplars
products:
  - Elasticsearch Serverless
---

# Query Prometheus exemplars

Authentication: required

Availability: Preview

## Paths

- `POST` (also `GET`) `/_prometheus/{index}/api/v1/query_exemplars`
- `POST` (also `GET`) `/_prometheus/api/v1/query_exemplars`

#### Path parameters

- `index` (string) — optional, leave it out to use `/_prometheus/api/v1/query_exemplars`
  An index expression that restricts which indices are considered, for example `metrics-generic.prometheus-*`.
If you omit it, the default expression `metrics-*` is used.
Only indices with `index.mode: time_series` are considered.
An alias is accepted and index privileges are checked against that alias name.

## Description

Get the exemplars of the series selected by a PromQL expression over a time range.
The endpoint mirrors the Prometheus `/api/v1/query_exemplars` endpoint.

GET requests send parameters in the query string.
POST requests send the same parameters as an `application/x-www-form-urlencoded` body.
Form-encoded POST requests are accepted only on authenticated TLS connections.
If you send the same parameter in both the query string and the form body, the API returns `400` with the standard Elasticsearch error body.

## Required privileges

- Index privileges: `read`

## Query string parameters

- `query` (string) — required
  The PromQL expression that selects the series.
- `start` (string) — required
  The start of the range, as an RFC 3339 timestamp or Unix time in seconds.
- `end` (string) — required
  The end of the range, as an RFC 3339 timestamp or Unix time in seconds.
- `timeout` (string · default: 2m) — optional
  The evaluation timeout, as a number of seconds or a duration such as `30s`.
It must be positive: `0` is rejected with status code `400`.
The default and the maximum are the `xpack.prometheus.query.timeout` cluster setting.
A request can only lower that cap.
Set the cluster setting to `-1` to remove the default and the maximum; a positive `timeout` is then uncapped.
When the timeout elapses, the response is `503` with `errorType` `timeout`.

## Responses

#### `200`

`application/json`

- `status` (string)
  The status of the request: `success`.
- `data` (object[])
  The exemplars, grouped by series.
  - `seriesLabels` (map string to string)
    The labels of the series that the exemplars belong to.
  - `exemplars` (object[])
    - `labels` (map string to string)
      The labels of the exemplar, such as `trace_id`.
    - `value` (string)
      The exemplar value, as a string.
    - `timestamp` (number)
      The exemplar timestamp, in Unix seconds.
#### `400`


The request or expression is not valid, including a non-positive `timeout`.
A form parameter that is also in the query string is the standard Elasticsearch error body instead.

`application/json`

- `status` (enum)
  The status of the request: `error`.
  Values: `error`
- `errorType` (enum)
  The Prometheus error type, from the HTTP status: `400` is `bad_data`; `503`, `408`, and `504` are `timeout`; every other status is `execution`.

Supported values include:
  - `bad_data`: HTTP `400`. The request or expression is not valid.
  - `timeout`: HTTP `503`, `408`, or `504`. The query timed out or a gateway timed out.
  - `execution`: Every other status, including HTTP `403` and `500`.
  Values: `bad_data`, `timeout`, `execution`
- `error` (string)
  The error message.
#### `403`


The caller is not allowed to run the query.

`application/json`

- `status` (enum)
  The status of the request: `error`.
  Values: `error`
- `errorType` (enum)
  The Prometheus error type, from the HTTP status: `400` is `bad_data`; `503`, `408`, and `504` are `timeout`; every other status is `execution`.

Supported values include:
  - `bad_data`: HTTP `400`. The request or expression is not valid.
  - `timeout`: HTTP `503`, `408`, or `504`. The query timed out or a gateway timed out.
  - `execution`: Every other status, including HTTP `403` and `500`.
  Values: `bad_data`, `timeout`, `execution`
- `error` (string)
  The error message.
#### `406`


Form-encoded POST is not accepted when security is disabled, HTTP TLS is not enabled on Elasticsearch, or the caller is anonymous.

`application/json`

- `error` (object)
  - `type` (string)
    The type of error
  - `reason` (union string) — nullable
    A human-readable explanation of the error, in English.
    One of: `string`
  - `stack_trace` (string)
    The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
  - `caused_by` (object) — recursive
    Same fields as `error`
  - `root_cause` (object[]) — recursive
    Same fields as `error`
  - `suppressed` (object[]) — recursive
    Same fields as `error`
- `status` (number)
#### `500`


The query ran, but the response could not be written.

`application/json`

- `status` (enum)
  The status of the request: `error`.
  Values: `error`
- `errorType` (enum)
  The Prometheus error type, from the HTTP status: `400` is `bad_data`; `503`, `408`, and `504` are `timeout`; every other status is `execution`.

Supported values include:
  - `bad_data`: HTTP `400`. The request or expression is not valid.
  - `timeout`: HTTP `503`, `408`, or `504`. The query timed out or a gateway timed out.
  - `execution`: Every other status, including HTTP `403` and `500`.
  Values: `bad_data`, `timeout`, `execution`
- `error` (string)
  The error message.
#### `503`


The query timed out.

`application/json`

- `status` (enum)
  The status of the request: `error`.
  Values: `error`
- `errorType` (enum)
  The Prometheus error type, from the HTTP status: `400` is `bad_data`; `503`, `408`, and `504` are `timeout`; every other status is `execution`.

Supported values include:
  - `bad_data`: HTTP `400`. The request or expression is not valid.
  - `timeout`: HTTP `503`, `408`, or `504`. The query timed out or a gateway timed out.
  - `execution`: Every other status, including HTTP `403` and `500`.
  Values: `bad_data`, `timeout`, `execution`
- `error` (string)
  The error message.
## Code examples

#### Console

```console
POST /_prometheus/api/v1/query_exemplars?query=http_request_duration_seconds_bucket&start=2026-07-09T22:00:00Z&end=2026-07-09T22:01:00Z
```

#### JavaScript

```javascript
const response = await client.prometheus.queryExemplars({
  query: "http_request_duration_seconds_bucket",
  start: "2026-07-09T22:00:00Z",
  end: "2026-07-09T22:01:00Z",
});
```

#### Python

```python
resp = client.prometheus.query_exemplars(
    query="http_request_duration_seconds_bucket",
    start="2026-07-09T22:00:00Z",
    end="2026-07-09T22:01:00Z",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_prometheus/api/v1/query_exemplars?query=http_request_duration_seconds_bucket&start=2026-07-09T22:00:00Z&end=2026-07-09T22:01:00Z" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### PHP

```php
$resp = $client->prometheus()->queryExemplars([
    "query" => "http_request_duration_seconds_bucket",
    "start" => "2026-07-09T22:00:00Z",
    "end" => "2026-07-09T22:01:00Z",
]);
```

#### Ruby

```ruby
response = client.prometheus.query_exemplars(
  query: "http_request_duration_seconds_bucket",
  start: "2026-07-09T22:00:00Z",
  end: "2026-07-09T22:01:00Z"
)
```

## Response examples

#### A successful response

`application/json`

A successful response from `GET /_prometheus/api/v1/query_exemplars`.

```json
{
  "status": "success",
  "data": [
    {
      "seriesLabels": {
        "__name__": "http_request_duration_seconds_bucket",
        "job": "api",
        "le": "0.5"
      },
      "exemplars": [
        {
          "labels": {
            "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736"
          },
          "value": "0.42",
          "timestamp": 1783634412.5
        }
      ]
    }
  ]
}
```

#### 400

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "status": "error",
  "errorType": "bad_data",
  "error": "string"
}
```

#### 403

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "status": "error",
  "errorType": "bad_data",
  "error": "string"
}
```

#### 406

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "error": {
    "type": "string",
    "reason": "string",
    "stack_trace": "string",
    "caused_by": {
      "type": "string",
      "reason": "string",
      "stack_trace": "string",
      "caused_by": {
        "type": "string",
        "reason": "string",
        "stack_trace": "string",
        "caused_by": {
          "type": "string",
          "reason": "string",
          "stack_trace": "string",
          "caused_by": {
            "type": "string",
            "stack_trace": "string"
          },
          "root_cause": [],
          "suppressed": []
        },
        "root_cause": [
          {
            "type": "string",
            "stack_trace": "string"
          }
        ],
        "suppressed": [
          {
            "type": "string",
            "stack_trace": "string"
          }
        ]
      },
      "root_cause": [
        {
          "type": "string",
          "reason": "string",
          "stack_trace": "string",
          "caused_by": {
            "type": "string",
            "stack_trace": "string"
          },
          "root_cause": [],
          "suppressed": []
        }
      ],
      "suppressed": [
        {
          "type": "string",
          "reason": "string",
          "stack_trace": "string",
          "caused_by": {
            "type": "string",
            "stack_trace": "string"
          },
          "root_cause": [],
          "suppressed": []
        }
      ]
    },
    "root_cause": [
      {
        "type": "string",
        "reason": "string",
        "stack_trace": "string",
        "caused_by": {
          "type": "string",
          "reason": "string",
          "stack_trace": "string",
          "caused_by": {
            "type": "string",
            "stack_trace": "string"
          },
          "root_cause": [],
          "suppressed": []
        },
        "root_cause": [
          {
            "type": "string",
            "stack_trace": "string"
          }
        ],
        "suppressed": [
          {
            "type": "string",
            "stack_trace": "string"
          }
        ]
      }
    ],
    "suppressed": [
      {
        "type": "string",
        "reason": "string",
        "stack_trace": "string",
        "caused_by": {
          "type": "string",
          "reason": "string",
          "stack_trace": "string",
          "caused_by": {
            "type": "string",
            "stack_trace": "string"
          },
          "root_cause": [],
          "suppressed": []
        },
        "root_cause": [
          {
            "type": "string",
            "stack_trace": "string"
          }
        ],
        "suppressed": [
          {
            "type": "string",
            "stack_trace": "string"
          }
        ]
      }
    ]
  },
  "status": 0
}
```

#### 500

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "status": "error",
  "errorType": "bad_data",
  "error": "string"
}
```

#### 503

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "status": "error",
  "errorType": "bad_data",
  "error": "string"
}
```

