|docs

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

View as Markdown

Availability

See the Incident Workflow Actions Overview table for the plans this workflow is available on.

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

  1. If you have not done so, follow the instructions to Create an Incident Workflow.
  2. When the instructions prompt you to add actions, select this action.
  3. Enter the following Inputs and click Save.
  4. Continue following instructions to Publish the Workflow.
  5. 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.


NameDescription
ConnectionThe 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 PatternIndex pattern to search. Default: metrics-*, which covers classic APM (metrics-apm.*), OpenTelemetry-native (metrics-*.otel-*), and custom metric indices.
Query TypeQuery DSL (default) or Lucene. See Query Types below.
QueryFor 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 ResultsMaximum number of hits to return. Allowed range: 1–1000. Default: 100.

Query Types

Query DSL — Query must be a JSON object containing the full _search request body, so you can use query, aggs, sort, _source, and size. PagerDuty sends it to POST /<Index Pattern>/_search. If the body sets size, it is capped at Max Results; if it does not, Max Results is used. Set "size": 0 for an aggregation-only search that returns no hits. Invalid JSON, or a size that is not a non-negative integer, produces an error.

Lucene — Sent to _search as a query_string query 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

NameDescription
ResultsJSON array of hits returned by Elasticsearch. Empty when the search uses "size": 0 or returns no hits.
AggregationsThe raw aggregations object returned by Elasticsearch. Empty when the query has no aggregations.
Total HitsTotal matching documents. This is a lower bound when Elasticsearch stops counting at its track_total_hits limit.
Search DurationQuery execution time as reported by Elasticsearch (for example 18ms).
ResultSuccess or Failed.
Result SummaryBrief 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.
ErrorPopulated when the action fails (for example authentication, an invalid index pattern, or invalid Query DSL).