Skip to main content
Version: 6.0

bin

Description

Splits continuous numeric values into discrete sets (bins) based on the specified field <field>.

Syntax

| bin [<bin-options>...] <field> [AS <newfield>]

Required Arguments

ParameterSyntaxDescription
field<field>The name of the field by which data is binned.

Optional Arguments

Defines limits and parameters for splitting data during analysis:

ParameterSyntaxDefaultDescription
binsbins=<int>100Maximum number of bins for calculation.
spanspan = (+|-)<int>(s|m|h|d|w|month)See predefined spansThe interval for binning.
newfieldas <field>A new name for the field.

The following format is accepted for time-based parameters: (+|-)<int>(s|m|h|d|w|month):

  • s/sec/secs/second/seconds - seconds
  • m/min/mins/minute/minutes - minutes
  • h/hr/hrs/hour/hours - hours
  • d/day/days - days
  • w/week/weeks - weeks
  • mon/month/months - months
Predefined span values

If the span parameter for a time field is not specified, predefined span parameters will be applied.

List of predefined span parameters:

Time Intervalspan
Last 15 minutes10 seconds
Last 60 minutes1 minute
Last 4 hours5 minutes
Last 24 hours30 minutes
Last 7 days1 day
Last 30 days1 day
Last year1 month

If the span parameter for a numeric field is not specified, it is calculated as (maximum field value) / (maximum number of bins).

warning

A time-based span (<int>(s|m|h|d|w|month)) cannot be specified for a numeric field, and a numeric span (<int>) cannot be specified for a time-based field.


Query Examples

The following examples use the auth_sessions index:

@timestampuserhostactionbytes
2026-06-24T08:00:00Zadmindc-01logged-in1500
2026-06-24T08:15:00Zadmindc-01file-access3200
2026-06-24T08:30:00Zadminsrv-01logged-in800
2026-06-24T09:00:00Zjohn.doeworkstation-01logged-in1200
2026-06-24T09:10:00Zjohn.doeworkstation-01file-access4500
2026-06-24T09:20:00Zjohn.doeworkstation-02logged-in950
2026-06-24T10:00:00Zguestkiosk-01logged-in300

Example 1

In this example, bin rounds the time field @timestamp down to the nearest 30 minutes. stats counts the number of events in each interval.

source auth_sessions
| bin span=30m @timestamp
| stats count by @timestamp

Events at 08:00 and 08:15 fall into one interval 08:00, events at 09:00, 09:10, and 09:20 fall into the 09:00 interval:

@timestampcount
2026-06-24T08:00:00.000Z2
2026-06-24T08:30:00.000Z1
2026-06-24T09:00:00.000Z3
2026-06-24T10:00:00.000Z1

Example 2

In this example, bin divides the numeric field bytes into intervals of width 1000. stats counts the number of events in each range.

source auth_sessions
| bin span=1000 bytes
| stats count by bytes
bytescount
0 - 10003
1000 - 20002
3000 - 40001
4000 - 50001

Example 3

In this example, the rounding result is saved to a new field bytes_bucket via as, the original field bytes remains unchanged.

source auth_sessions
| bin span=1000 bytes as bytes_bucket
| table @timestamp, user, bytes, bytes_bucket
@timestampuserbytesbytes_bucket
2026-06-24T08:00:00Zadmin15001000 - 2000
2026-06-24T08:15:00Zadmin32003000 - 4000
2026-06-24T08:30:00Zadmin8000 - 1000
2026-06-24T09:00:00Zjohn.doe12001000 - 2000
2026-06-24T09:10:00Zjohn.doe45004000 - 5000
2026-06-24T09:20:00Zjohn.doe9500 - 1000
2026-06-24T10:00:00Zguest3000 - 1000

Example 4

In this example, the parameter bins=3 sets the maximum number of intervals. The interval width is calculated automatically as max_value / bins - for the bytes field this is 4500 / 3 = 1500.

source auth_sessions
| bin bins=3 bytes
| stats count by bytes
bytescount
0 - 15004
1500 - 30001
3000 - 45001