Identifies the event with the maximum value in a specified field and returns selected fields from that event.
The resulting event contains only the fields specified in the
include
parameter.
If multiple events share the same maximum value, the
selectFromMax()
function returns one of
those events randomly (non-deterministic way).
Hide omitted argument names for this function
Omitted Argument NamesThe argument name for
field
can be omitted; the following forms of this function are equivalent:logscale SyntaxselectFromMax("value",include=["value"])
and:
logscale SyntaxselectFromMax(field="value",include=["value"])
These examples show basic structure only.
selectFromMax()
Examples
Click
next to an example below to get the full details.Find Most Recent (Latest) Value of Field X
Find the most recent (latest) value of field X using the
selectFromMax()
function
Query
selectFromMax(@timestamp, include=[x, @timestamp])
Introduction
In this example, the selectFromMax()
function is
used to find the most recent (latest) value of the field
x and return the timestamp when
that value was recorded.
Step-by-Step
Starting with the source repository events.
- logscale
selectFromMax(@timestamp, include=[x, @timestamp])
Sorts all events by timestamp, then selects the event in field x with the highest (most recent) timestamp, returning only the specified fields x and @timestamp.
In this example,
selectFromMax()
filters for the "maximum value" of @timestamp, and finds the event with the newest/latest timestamp in the event set that also contains the specified field x. Timestamps are typically stored as numerical values (often in Unix epoch format), where larger numbers represent more recent times.The
include
parameter is used to specify which fields to include in the output. Event Result set.
Summary and Results
The query is used to find the most recent value of field x by selecting the event with the highest (most recent) timestamp value.
Using this query is an efficient way to find the latest value since it does not require sorting all results or using other aggregation functions - the query directly selects the most recent matching event.