﻿---
title: ES|QL aggregation functions
description: The STATS and INLINE STATS commands support these aggregate functions: 
url: https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# ES|QL aggregation functions
The [`STATS`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/commands/stats-by) and [`INLINE STATS`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/commands/inlinestats-by) commands support these aggregate functions:
- [`ABSENT`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/absent) <applies-to>Elastic Stack: Generally available since 9.2</applies-to>
  Returns true if the input expression yields no non-null values.
- [`AVG`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/avg)
  Returns the average of a numeric field.
- [`COUNT`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/count)
  Returns the total number of input values.
- [`COUNT_DISTINCT`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/count_distinct)
  Returns the approximate number of distinct values.
- [`EARLIEST`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/earliest) <applies-to>Elastic Stack: Generally available since 9.4</applies-to>
  Returns the earliest value of a field sorted by timestamp.
- [`FIRST`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/first) <applies-to>Elastic Stack: Generally available since 9.4</applies-to>
  Returns the earliest occurrence of a field based on a sort field.
- [`LAST`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/last) <applies-to>Elastic Stack: Generally available since 9.4</applies-to>
  Returns the latest occurrence of a field based on a sort field.
- [`LATEST`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/latest) <applies-to>Elastic Stack: Generally available since 9.4</applies-to>
  Returns the latest value of a field sorted by timestamp.
- [`MAX`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/max)
  Returns the maximum value of a field.
- [`MEDIAN`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/median)
  Returns the median value of a numeric field.
- [`MEDIAN_ABSOLUTE_DEVIATION`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/median_absolute_deviation)
  Returns the median absolute deviation, a robust measure of variability.
- [`MIN`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/min)
  Returns the minimum value of a field.
- [`PERCENTILE`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/percentile)
  Returns the value at which a certain percentage of observed values occur.
- [`PRESENT`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/present) <applies-to>Elastic Stack: Generally available since 9.2</applies-to>
  Returns true if the input expression yields any non-null values.
- [`SAMPLE`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/sample) <applies-to>Elastic Stack: Generally available since 9.1</applies-to>
  Collects sample values for a field.
- [`SPARKLINE`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/sparkline) <applies-to>Elastic Stack: Planned</applies-to> <applies-to>Elastic Cloud Serverless: Preview</applies-to>
  Computes y-axis values of a sparkline graph for an aggregation over time.
- [`ST_CENTROID_AGG`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/st_centroid_agg) <applies-to>Elastic Stack: Preview</applies-to> <applies-to>Elastic Cloud Serverless: Preview</applies-to>
  Calculates the spatial centroid over a field with geometry type.
- [`ST_EXTENT_AGG`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/st_extent_agg) <applies-to>Elastic Stack: Preview</applies-to> <applies-to>Elastic Cloud Serverless: Preview</applies-to>
  Calculates the spatial extent bounding box over a field with geometry type.
- [`STD_DEV`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/std_dev)
  Returns the population standard deviation of a numeric field.
- [`SUM`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/sum)
  Returns the sum of a numeric expression.
- [`TOP`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/top)
  Collects the top values for a field, including repeated values.
- [`VALUES`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/values) <applies-to>Elastic Stack: Preview</applies-to> <applies-to>Elastic Cloud Serverless: Preview</applies-to>
  Returns unique deduplicated values as a multivalued field.
- [`VARIANCE`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/variance)
  Returns the population variance of a numeric field.
- [`WEIGHTED_AVG`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/pull/151137/reference/query-languages/esql/functions-operators/aggregation-functions/weighted_avg)
  Returns the weighted average of a numeric expression.