Histogram

Histogram aggregation

/ Histogram, / Aggregation

Histogram aggregation #

A multi-bucket aggregation over numeric fields that applies a fixed interval to build the buckets. It answers “how are the values distributed?” — every document lands in exactly one bucket, and the bucket keys form a regular grid over the value axis.

How it works #

Each document’s value v is placed by index arithmetic — bucket index floor((v - offset) / interval) — so a bucket covers the half-open window [key, key + interval). Buckets accumulate in a sorted map, and the response lists them by ascending key.

...

Date histogram aggregation

/ Date, / Histogram, / Aggregation

Date histogram aggregation #

This multi-bucket aggregation is similar to the normal histogram, but it can only be used with date fields. Dates are represented internally as epoch milliseconds, so the plain histogram can technically run on them too — but calendar intervals are not a fixed length (a month is 28–31 days), which is exactly what this aggregation handles.

How it works #

Date fields store epoch milliseconds at ingest, and the aggregation builds its grid on those numbers. calendar_interval and fixed_interval select between two grid types (exactly one must be set):

...