Docs

v2.0

top() function

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

Function type: Selector
Output data type: Object

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

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:"telegraf/autogen")
  |> 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)

Bug Reports and Feedback

Thank you for being willing to help test InfluxDB v2.0 alpha! Feedback and bug reports are welcome and encouraged both for InfluxDB and this documentation.

Submit feedback in the InfluxData Community