Elastic Content Share

Aggregate response codes and service errors with ES|QL STATS

Summarize Elasticsearch log events with ES|QL STATS to count response codes, calculate total bytes, and find operational patterns faster.

Use STATS when you want ES|QL to summarize many Elasticsearch documents into a smaller result set. This example counts web responses by status code and destination country so you can quickly spot error patterns.

FROM kibana_sample_data_logs
| WHERE @timestamp >= NOW() - 24 hours
| STATS events = COUNT(*), total_bytes = SUM(bytes) BY response.keyword, geo.dest
| SORT events DESC
| LIMIT 20

Why this ES|QL pattern helps

A raw event list is useful for inspection, but operations teams often need a grouped view first. STATS turns logs into metrics you can sort, visualize, save to a dashboard, or use as the starting point for a deeper investigation.

What to change for your data

When to use it

This pattern fits Kibana dashboard panels, ES|QL alert previews, service health checks, and support workflows where users search for Elasticsearch ES|QL aggregation examples.

Source reference: Elastic documentation: Use ES|QL in the Kibana UI.