---
type: api
title: Get the Elasticsearch query for a rule
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-get-alerting-rule-id-query-inspector
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-get-alerting-rule-id-query-inspector
products:
  - Kibana
---

# Get the Elasticsearch query for a rule

- Server: `https://{kibana_url}`

## Paths

- `GET` `/api/alerting/rule/{id}/query_inspector`
- `GET` `/s/{space_id}/api/alerting/rule/{id}/query_inspector`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/kibana/authentication#basicauth)

#### Path Parameters

- `id` (string)
  The identifier for the rule.

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Returns the Elasticsearch query that a rule executes, and optionally its response.

## Query String Parameters

- `mode` (enum  · default: build)
  The inspection mode. Use "build" to return only the query, or "execute" to run the query and include the response.
  Values: `build`, `execute`
- `alert_id` (string)
  The alert document ID. When provided, the query inspector uses the evaluation time range from the alert instead of the current time.

## Responses

#### `200`

Indicates a successful call.

`application/json`

- `queries` ([] object · max: 1000)
  - `index` (string)
  - `label` (string)
  - `request` (map string to object)
  - `response` (map string to object)
#### `400`

Indicates the rule type is not supported or the request parameters are invalid.

#### `404`

Indicates a rule with the specified rule ID does not exist.

## Code Examples

#### Console

```console
GET /api/alerting/rule/{id}/query_inspector
```

#### curl

```curl
curl -X GET "https://{kibana_url}/api/alerting/rule/{id}/query_inspector"
```

## Response Examples

#### A query inspector response for a custom threshold rule

```json
{
  "queries": [
    {
      "index": "metrics-*",
      "request": {
        "aggs": {
          "groupings": {
            "composite": {
              "size": 500,
              "sources": []
            }
          }
        },
        "query": {
          "bool": {
            "filter": [
              {
                "range": {
                  "@timestamp": {
                    "gte": "2026-01-01T00:00:00.000Z",
                    "lte": "2026-01-01T00:05:00.000Z"
                  }
                }
              }
            ]
          }
        },
        "size": 0
      }
    }
  ]
}
```

