Formatting Values
Internally timestamps are stored as a epoch (number of seconds since 1st Jan 1970) at millisecond accuracy. The UI automatically displays the @timestamp and @ingesttimestamp as human readable dates.
For examples of formatting or extracting different time values, see Extracting Specific Time Values. For examples of more complex formatting of dates or times from a given time value, see Formatting Dates or Times.
Formatting Numerical Values
There are a number of functions available for formatting numbers:
The main function for formatting numbers if
format(). This uses the same basic formatting system as used in Java or the C libraryprintf(). For example, to format a floating point number:logscaleformat("%,.2f", field=avg, as=avg)Or to format a number with commas separating the 1,000s:
logscaleformat("%,i", field=_count, as=_count)format()can round floating point numbers, but to round numbers, especially if you need to round up or down, use theround():logscaleround(bytes,how=floor)If the number is large or is based on a byte-based value (i.e. megabytes or gigabytes), metric, or seconds, use
unit:convert(), which allows for conversion up or down. For example, to convert a byte value into MB:logscalerate:=128*1024 | unit:convert(rate, as="rate", to="M")
Rotating (Transposing) Tables
Occasionally you may want to rotate a given table to filter or display the contents in a different orientation. For example, with a query like this which searches for PHP events and counts the hosts:
/php/
| groupBy([host],function=count(),limit=5)The output might look like:
| host | _count |
|---|---|
| BACKUP01 | 2 |
| DEV-DB01 | 2 |
| MAIL01 | 4 |
| NYC-SRV01 | 1 |
| PRINT01 | 1 |
By swapping the columns for rows (and vice versa) creates a table with two rows (host and _count):
| column | row[1] | row[2] | row[3] | row[4] | row[5] |
|---|---|---|---|---|---|
| _count | 2 | 2 | 4 | 1 | 1 |
| host | BACKUP01 | DEV-DB01 | MAIL01 | NYC-SRV01 | PRINT01 |
This is achieved by adding the transpose():
/php/
| groupBy([host],function=count(),limit=5)