Skip to content

Median Aggregation

Edit page

A single-value metrics aggregation that computes the median of numeric values that are extracted from the aggregated documents.

The median is the value separating the higher half from the lower half of a data sample, it may be thought of as the “middle” value. 1

TypeDescriptionExampleResult
Mean (or Average)Sum of values of a data set divided by number of values(1+2+2+3+4+7+9) / 74
MedianMiddle value separating the greater and lesser halves of a data set1, 2, 2, 3, 4, 7, 93
ModeMost frequent value in a data set1, 2, 2, 3, 4, 7, 92

The aggregation takes {"_median": {"_field": "<field_name>"}}. With an even number of values the median is the mean of the two middle ones. Every value of every bucket is held in memory and shipped with the aggregation, so the cost grows with the number of documents (there is no cap).

SEARCH /bank/
{
"_query": "*",
"_limit": 0,
"_check_at_least": 1000,
"_aggs": {
"balance_median": {
"_median": {
"_field": "balance"
}
}
}
}

1 Median