Documentation

top() function

The top() function sorts a table by columns and keeps only the top n records.

Function type: Selector
Output data type: Record

top(n:10, columns: ["_value"])

Empty tables

top() drops empty tables.

Parameters

n

Number of records to return.

Data type: Integer

columns

List of columns by which to sort. Sort precedence is determined by list order (left to right). Default is ["_value"].

Data type: Array of strings

Examples

from(bucket:"example-bucket")
  |> range(start:-1h)
  |> filter(fn: (r) =>
    r._measurement == "mem" and
    r._field == "used_percent"
  )
  |> top(n:10)

Function definition

// _sortLimit is a helper function, which sorts and limits a table.
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
  tables
    |> sort(columns:columns, desc:desc)
    |> limit(n:n)

top = (n, columns=["_value"], tables=<-) => _sortLimit(n:n, columns:columns, desc:true)

New! Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: