Syntax and Structure for chart/stats

The chart/stats operators apply aggregate operations over a collection of events and/or results from an operator chaining query. They display search results for specified fields in the Search Results table.

For additional information about the construction and usage of the chart/stats operators, see the chart/stats overview, Aggregate Functions for chart/stats, and Cheat Sheet for chart/stats.

Syntax

...| chart <function>  ( <decorator> field ) as <customName> , …, by <field>, <…moreFields> span <timeField> = timeBucket
...| stats <function>  ( <decorator> field ) as <customName> , …, by <field>, <…moreFields> span <timeField> = tiemBucket​

Operator name: | chart , | stats

The user can use chart or stats to set an aggregation query in the search bar. Chart and stats keywords are considered synonyms, and the behavior and results will be the same.

Functions: <function> ( <decorator> field ) as <customName>

Chart and stats operators can apply the following list of functions over a group of events:

Query input within [ ] (straight brackets) is optional for the query syntax.



Input within < > (angle brackets) indicates users may enter their own input:

... | rename <source_name> as <NewSourceName>
Available functions for chart/stats pipe operators
Aggregate Function Dataype
Count

Count Distinct
All datatypes
Min, Max Numbers
Average (Agg.),

Standard deviation (Stdev),

Sum
Numbers
Earliest, Latest Dates

The following examples highlight several scenarios for how events are counted.

Aliases that contain special characters have the following syntax restrictions:

Syntax Restrictions for Special Characters
Special Characters Restrictions Examples
+, *, &, !, - , = , <, >, | Need to be enclosed in single/double quotes when they are reused and the search works as expected. | rename file path as 'FP+DEV' | chart count ( 'FP+DEV' ) by 'FP+DEV'
@, #, +, ?, /, ^, [], {}, _ , *, ., ~, $, % Do not need to be enclosed in single/double quotes when they are reused and the search runs as expected. | rename file path as 'FP$DEV' | chart count ( FP$DEV ) by FP$DEV
\

When a backslash is used in an alias name, add an additional backslash \ to escape the character. It does not need to be enclosed in single/double quotes when it is reused and the search runs as expected.

The outcome field name should show only one backslash.

| rename file path as 'FP\\DEV' | chart count ( FP\\DEV ) by FP\\DEV

Grouping Events

The chart/stats pipe operators group events based on two strategies: by field and by time bucket. By default chart and stats operators need at least one "by field" in order to group data.

The chart/stats Aggregate Functions are discussed in detail in a separate topic.

The following examples are based on a simplified version of the Events Table below.

Simplified Events Table
Name Category

Outcome
Destination

Hostname
Normalized

Event Time
Bytes

In
BCtType /Interrupt 11.12.11.19 12/29/22

10:34:15.635
3404
ArstType /Failure 45.67.89.112 12/29/22

1-:34:15.635
3022
BCtType /Failure 10-.12.93.6 12/29/22

11:34:15.635
3009
FtType /Success 45.67.89.112 12/29/22

12:34:15.635
3216
MSType /Interrupt 45.67.89.112 11/04/22

10:10:02.000
3063
MSType /Interrupt 10.12.93.6 12/29/22

11:32:54.064
3409
Summary from the Simplified Events Table, grouped by the Name field
Name Number of Events
ArstType 1
BCtType 2
Row summary from the Simplified Events Table, grouped by the Name field
Name Category

Outcome
Number of

Events
ArstType /Failure 1
BCtType /Failure 1
BCtType /Interrupt 1
FtType /Success 1
MSType /Interrupt 2

"Group by" Expressions

Group by expressions: by <field>, <…moreFields>

The group by expressions are separated by commas. The fields used in this part of the query work to organize the events. There is a hierarchy for the fields used.

 ... | chart count (name), sum(bytes in)

This organizes the query syntax by category outcome, destination and hostname. The operator creates groups based on the combinations of category outcome and destination hostname.

Time bucket grouping: span <timeField> = tiemBucket

This is another way to apply grouping based on time buckets. A time bucket can be set using the following syntax:

Simple scale: 1d (one day), 2m (two minutes), 35s (thirty five seconds)

Complex scale: 1d2m (one day and two minutes). Complex scales must be organized with the highest order period of time to the lowest.

Time scales used to represent time buckets
Time Bucket Representation
Days 1d, 20d
Hours 4h
Minutes 2m
Seconds 12s
Time buckets only work with Normalized event Time, Device Event Time, and Database Event Time. This group strategy is optional. If used, it is applied at the beginning of the calculations before any "by expressions."

Allowed syntax to define span expressions (grouping by time)

...| chart count (name), sum(bytes in) by category outcome span 1h (Date-picker field time is used)

...| chart count (name), sum(bytes in) by category outcome span = 1h (Date-picker field time is used)

...| chart count (name), sum(bytes in) by category outcome span Normalized event time = 1h

Rules and exceptions

 

For information about other operators, functions, and syntax requirements, see Use an Operator in the Query.