On this page
bin command
Put each value of a field into a bucket: a timestamp into a time bucket, a number into a range such as 200-300.
Puts each value of a field into a bucket and replaces the value with that bucket. A later stats grouped by the field then counts or measures each bucket rather than each distinct value.
A timestamp becomes the start of its time bucket, so 14:07 and 14:52 both become 14:00 in one-hour buckets. A number becomes its range as text, such as 200-300, which includes the lower edge and stops just short of the upper one.
Add AS to write the bucket to a new field and keep the original value as it was.
Syntax
| bin [span=<width>] [bins=<count>] [minspan=<width>] [aligntime=<time>] [<timestamp field>] [AS <new field>]
| bin span=<width> <number field> [AS <new field>]
| bin bins=<count> start=<number> end=<number> <number field> [AS <new field>]Square brackets mark an optional part, and angle brackets a value you supply.
Arguments
| Argument | Required | Description |
|---|---|---|
<field> | Optional | The field to bin. One per stage. Defaults to _time, so | bin span=1m bins the event time. Options may go before or after it, so | bin _time span=1h and | bin span=1h _time are the same. |
span=<width> | Optional | The width of each bucket. For a timestamp, a time such as 30s, 5m, 1h, 1d or 1w, or a plain number of seconds. For a number, a plain width such as 100 or 0.5, or a log span: log10 (or just log) makes buckets 1-10, 10-100, 100-1000, log2 doubles each time, and 2log10 makes 2-20, 20-200. Leave it off, or write auto, to size time buckets from the search's time range. |
bins=<count> | Optional | The most buckets to make. For a timestamp, the time range is divided into about this many buckets, rounded up to a familiar width such as 5m or 1h. For a number, it divides the range from start to end, using a power of ten as the width, so there may be fewer buckets than asked for. Defaults to 100 for a number. |
minspan=<width> | Optional | The narrowest bucket automatic sizing may pick for a timestamp, such as 1m. Has no effect beside span=. |
start=<number> | Optional | The low end of the range bins= divides, for a number field. |
end=<number> | Optional | The high end of the range bins= divides, for a number field. |
aligntime=<time> | Optional | Where time buckets start counting from. earliest starts them at the beginning of the search's time range and latest at its end. A time such as 2026-06-30T09:30:00 starts them there. Without it, buckets line up with whole minutes, hours and days in UTC. |
AS <new field> | Optional | Write the bucket to this field and leave the original field unchanged. |
Usage
- A number bucket is text, such as 100-200, so sorting by it sorts the text. Ranges with the same number of digits sort in order.
- A value that is not a number gets no number bucket and is left empty. A number at or below zero gets no log bucket.
- Binning a number needs span=, or bins= with start= and end=. Automatic sizing is only for timestamps, where the search's time range sets it.
- After a stats, bin a column of the result. To bin a field the stats grouped by, add AS with a new name, or bin before the stats.
- bin cannot follow dedup. Move it in front of the dedup.
- To chart a measure over time, timechart is shorter. Use bin when you want the buckets as a table, or want to bin a number.
Examples
1. Errors per hour for each service
level=error | bin _time span=1h | stats count() by _time, serviceOne row per hour and service. Unlike timechart, the result is a table you can keep shaping with where, sort and eval.
2. A latency histogram
| bin duration_ms span=100 | stats count() by duration_ms | sort duration_msHow many requests took 0-100 ms, 100-200 ms, and so on.
3. Response sizes by order of magnitude
| bin bytes span=log10 AS size | stats count() by sizeGroups sizes into 1-10, 10-100, 100-1000 and so on, keeping bytes itself unchanged.
4. Ten equal ranges of a score
| bin score bins=10 start=0 end=100 | stats count() by scoreDivides 0 to 100 into buckets 10 wide.
5. Buckets that start when the search does
| bin _time span=15m aligntime=earliest | stats count() by _timeEach 15 minute bucket starts at the beginning of the time range rather than on the quarter hour.