chart/stats

The chart/stats operators display search results for specified fields as fields in the Search Results table.

Syntax

...| chart count by field1, field2, field3 ... [span [time_field]=time_bucket]
...| chart {{sum | avg | min | max | } (field)}+ by field1, field2, field3 ...[span [time_field]= time_bucket]
...| chart {function (field)} as new_field_name by field [span [time_field]

For simple syntax examples, see below.

where:

"by" Statements

Simple Syntax Examples

Aggregation Functions

Aggregation functions only work on numeric fields. The specified fields must contain numeric values. If a field you specify is of the wrong data type, you will receive an error message like the following: "java.lang.NumberFormatException".

Aliases that contain special characters have the following syntax restrictions:

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

The Span Function

In addition to grouping events defined by eval operators, the span function groups events by a time field (such as EventTime or deviceReceiptTime) and a time bucket.

How Do I Use This?

Aggregation Function Examples

Span Function Examples

Grouping with span is useful in situations when you want to find out the number of occurrences in a specific time span.

 

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