Documentation

Query fields and tags

Use filter() to query data based on fields, tags, or any other column value. filter() performs operations similar to the SELECT statement and the WHERE clause in InfluxQL and other SQL-like query languages.

The filter() function

filter() has an fn parameter that expects a predicate function, an anonymous function comprised of one or more predicate expressions. The predicate function evaluates each input row. Rows that evaluate to true are included in the output data. Rows that evaluate to false are excluded from the output data.

// ...
    |> filter(fn: (r) => r._measurement == "example-measurement-name" )

The fn predicate function requires an r argument, which represents each row as filter() iterates over input data. Key-value pairs in the row record represent columns and their values. Use dot notation or bracket notation to reference specific column values in the predicate function. Use logical operators to chain multiple predicate expressions together.

// Row record
r = {foo: "bar", baz: "quz"}

// Example predicate function
(r) => r.foo == "bar" and r["baz"] == "quz"

// Evaluation results
(r) => true and true

Filter by fields and tags

The combination of from(), range(), and filter() represent the most basic Flux query:

  1. Use from() to define your bucket.
  2. Use range() to limit query results by time.
  3. Use filter() to identify what rows of data to output.
from(bucket: "example-bucket")
    |> range(start: -1h)
    |> filter(fn: (r) => r._measurement == "example-measurement-name" and r.mytagname == "example-tag-value")
    |> filter(fn: (r) => r._field == "example-field-name")

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered

InfluxDB Cloud powered by TSM