Min aggregation #
A single-value metrics aggregation that keeps track and returns the minimum value among numeric values extracted from the aggregated documents. It answers “how low does this field go” over any query — the floor of a price range, the earliest timestamp in a window, the cheapest item that matches a filter.
How it works #
The engine walks the matching documents once, keeping the smallest value seen;
any larger value costs one comparison. Values are coerced to doubles as they
are read — integers, floats and booleans (true = 1, false = 0) qualify,
non-numeric values such as keyword strings do not.
Documents that lack the field are skipped by default. With missing set,
the default is folded into the comparison whenever at least one candidate
document lacks the field — a missing document can therefore become the
minimum.
On the column-store fast path (the production executor) each segment’s
column is decoded once and reduced in a batch (min_f64), with
count_present deciding whether the missing default applies; segments and
shards combine by pairwise min, so distributed and single-node requests
return the same number. Everything is exact — no approximation is involved.
When no document contributed a value, the result is null — unlike
sum, an empty set has no meaningful minimum.
Examples #
Computing the min price value across all documents — the SQL pill beside
the Run button answers the same question with MIN(price):
POST /sales/_search
{
"aggs": {
"min_price": {
"min": {
"field": "price"
}
}
}
}
Response:
{
...
"aggregations": {
"min_price": {
"value": 15.0
}
}
}
As can be seen, the name of the aggregation (min_price above) also serves as
the key by which the aggregation result can be retrieved from the returned
response.
Use cases #
- Price floors.
sales.min(price)=15.0— the lowest price in the 120 teaching sales; pair it withmaxto state the full15..60range in one response. - Cheapest per group. Nested under
termsontype,mingives the entry price of each product line for a “starting at” label. - Catalogue extremes.
products.min(price)=5.0across the 30 products — find the loss-leader without sorting the whole index. - Bound checks. Alert when
mincrosses a threshold only a bad value could cross — a negative price, a zero quantity. - Framing distributions. Min and max bracket a
percentilesreport so outliers can’t hide behind the medians.
Parameters for min
#
field
(Required, string) Field you wish to aggregate.script
(Optional, object) Script evaluated per document as the value source — mutually exclusive withfield.missing
(Optional, number) Value used for documents missing the field; it takes part in the comparison, so it can become the minimum.
Related #
max— the mirror image of this aggregationstats— min and max plus count/avg/sum in one requestpercentiles— the whole distribution, not just the endsmin_bucket— min over another aggregation’s bucket values