This page is currently a work in progress; expect frequent near-term updates.
The pivot command makes simple pivot operations fairly simple, but can be pretty complex for more sophisticated pivot operations. Fundamentally this command is a wrapper around stats and xyseries. It doesn't necessarily add new behavior, but it may be easier to use if you're already familiar with the pivot operation.
This command is a generating command and must be first in a search pipeline. It requires a large number of inputs. You must specify the data model, the object, and the pivot search to run. The pivot search can include cells, rows, columns, filters, limits, row and column formatting, and row sort options.
Run pivot searches against a particular data model object.
| pivot <datamodel-name> <objectname> <pivot search>
- Syntax: <string>
- Description: The name of the data model to search.
- Syntax: <string>
- Description: The name of a data model object to search.
- pivot search
- Syntax: (<cellvalue>)* (SPLITROW <rowvalue>)* (SPLITCOL colvalue [options])* (FILTER <filter info>)* (LIMIT <limit info>)* (ROWSUMMARY <true|false>)* (COLSUMMARY <true|false>)* (SHOWOTHER <true|false>)* (NUMCOLS <num>)* (rowsort [options])*
- Description: The pivot search to run for the specified data model and object.
Pivot search options
The pivot search can include elements such as cell values, rows, columns, filters, limits, row and column formatting, and row sort options. Cell values always come first. They are followed by rows and columns, which can be interleaved, for example:
avg(val), SPLITCOL foo, SPLITROW bar, SPLITCOL baz.
Cell value element
- Syntax: <function>(fieldname) [AS <label>]
- Description: Define the values of a cell and optionally rename it. Here, "label" is the name of the cell in the report.
The set of allowed functions depend on the data type of field specified (fieldname):
- for strings: list, values, first, last, count, and distinct_count (dc).
- for numbers: sum, count, avg, max, min, stdev, list, and values.
- for timestamps: duration, earliest, latest, list, and values.
- for object or child counts: count.
Row split-by element
- Syntax: fieldname [AS <label>] [RANGE start=<value> end=<value> max=<value> size=<value>] [PERIOD (auto | year | month| day | hour | minute | second)] [TRUELABEL <label>] [FALSELABEL <label>]
- Description: You can have none, some, or all of these options on each SPLITROW. They may appear in any order. You can rename the field using "AS <label>", where "label" is the name of the row in the report.
Other options depend on the data type of the field specified (fieldname):
- RANGE applies only for numbers. The options (start, end, max, and size) do not all have to be specified.
- PERIOD applies only for timestamps. Use it to specify the period to bucket by.
- TRUELABEL applies only for booleans. Use it to specify the label for true values.
- FALSELABEL applies only for booleans. Use it to specify the label for false values.
Column split-by element
- <filter info>
- Syntax: <fieldname> <comparator> <value>
- Description: The comparator you can use for value expressions depends on the the type of field value.
- for strings: is, contains, isNot, doesNotContain, startsWith, endsWith,isNull, isNotNull, and regex
- ipv4: is, contains, isNot, doesNotContain, startsWith, isNull, isNotNull
- for numbers: =, !=, <, <=, >, >=, isNull, isNotNull
- for booleans: isNull, isNotNull, = or is
Example 1: This command counts the number of events in the "HTTP Requests" object in the "Tutorial" data model.
| pivot Tutorial HTTP_requests count(HTTP_requests) AS "Count of HTTP requests"
This can be formatted as a single value report in the dashboard panel:
Example 2: Using the Tutorial data model, create a pivot table for the count of "HTTP Requests" per host.
| pivot Tutorial HTTP_requests count(HTTP_requests) AS "Count" SPLITROW host AS "Server" SORT 100 host
| pivot myModel myObject avg(myValue) SPLITROW foo AS bar FILTER thing BY top 10 count(otherThing)
Have questions? Visit Splunk Answers and see what questions and answers the Splunk community has about using the pivot command.