For AI agents and assistants: visit https://docs.pagerduty.com/llms.txt for the index.
Workflow Actions
Elasticsearch: Search Metrics
Search APM and OpenTelemetry metric indices in Elasticsearch
Availability
Description
The action searches the metric indices that match Index Pattern using a full Query DSL _search request body or a Lucene query string, and returns the matching hits together with any aggregations. It is built for aggregations such as latency percentiles, error rate, and throughput over time, which help you see when and how a service degraded during an incident.
PagerDuty does not inject a default time range. For time-bounded results, add a range filter on @timestamp to your Query DSL body, or a range such as @timestamp:[now-1h TO now] to your Lucene query.
Prerequisites
- An Elasticsearch cluster reachable from PagerDuty over HTTPS.
- An Elasticsearch API key with read permission on the indices that match your Index Pattern.
- An Elasticsearch connection in PagerDuty. See the Elasticsearch subsection in Workflow Integrations.
Instructions
- If you have not done so, follow the instructions to Create an Incident Workflow.
- When the instructions prompt you to add actions, select this action.
- Enter the following Inputs and click Save.
- Continue following instructions to Publish the Workflow.
- When the action runs, you will see the Outputs listed below.
Inputs
Field References
Fields with the {+} icon accept Field References, which can be useful for referencing incident data or outputs created in prior workflow steps. To add Field References, click {+}, or enter {{, and select relevant fields. Refer to the Field References article for more information.
| Name | Description |
|---|---|
| Connection | The Elasticsearch Workflow Integration connection (Elasticsearch URL and API Key configured in PagerDuty). If you have not yet configured an Elasticsearch integration, see the Elasticsearch Integration instructions. |
| Index Pattern | Index pattern to search. Default: metrics-*, which covers classic APM (metrics-apm.*), OpenTelemetry-native (metrics-*.otel-*), and custom metric indices. |
| Query Type | Query DSL (default) or Lucene. See Query Types below. |
| Query | For Query DSL, the full _search request body as JSON, for example {"size": 0, "query": {...}, "aggs": {...}}. For Lucene, a query string, for example service.name:checkout AND metricset.name:service_transaction. |
| Max Results | Maximum number of hits to return. Allowed range: 1–1000. Default: 100. |
Query Types
Query DSL — Query must be a JSON object containing the full
_searchrequest body, so you can usequery,aggs,sort,_source, andsize. PagerDuty sends it toPOST /<Index Pattern>/_search. If the body setssize, it is capped at Max Results; if it does not, Max Results is used. Set"size": 0for an aggregation-only search that returns no hits. Invalid JSON, or asizethat is not a non-negative integer, produces an error.Lucene — Sent to
_searchas aquery_stringquery with your Query text, sorted newest first by@timestamp, with Max Results as the request size. Aggregations are not available with Lucene; switch to Query DSL to use them.
Example
The following Query DSL body returns the average transaction duration for the checkout service in five-minute buckets over the last hour. The metricset.name filter limits the search to service transaction metrics, and the metricset.interval filter keeps APM's 10m and 60m rollups from counting the same transactions again:
{
"size": 0,
"query": {
"bool": {
"filter": [
{ "term": { "service.name": "checkout" } },
{ "term": { "metricset.name": "service_transaction" } },
{ "term": { "metricset.interval": "1m" } },
{ "range": { "@timestamp": { "gte": "now-1h" } } }
]
}
},
"aggs": {
"over_time": {
"date_histogram": { "field": "@timestamp", "fixed_interval": "5m" },
"aggs": { "latency": { "avg": { "field": "transaction.duration.summary" } } }
}
}
}
The example assumes the classic Elastic APM (APM Server and ECS) schema. With native OpenTelemetry ingest, field names differ (for example, duration instead of transaction.duration.us).
Outputs
| Name | Description |
|---|---|
| Results | JSON array of hits returned by Elasticsearch. Empty when the search uses "size": 0 or returns no hits. |
| Aggregations | The raw aggregations object returned by Elasticsearch. Empty when the query has no aggregations. |
| Total Hits | Total matching documents. This is a lower bound when Elasticsearch stops counting at its track_total_hits limit. |
| Search Duration | Query execution time as reported by Elasticsearch (for example 18ms). |
| Result | Success or Failed. |
| Result Summary | Brief description of what the action did or why it failed. It also notes when Index Pattern matched no index and when results were capped at Max Results. |
| Error | Populated when the action fails (for example authentication, an invalid index pattern, or invalid Query DSL). |