Query fields and tags

Use the filter() function 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.

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

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.

  1. // Row record
  2. r = {foo: "bar", baz: "quz"}
  3. // Example predicate function
  4. (r) => r.foo == "bar" and r["baz"] == "quz"
  5. // Evaluation results
  6. (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.

    1. from(bucket: "example-bucket")
    2. |> range(start: -1h)
    3. |> filter(fn: (r) =>
    4. r._measurement == "example-measurement" and
    5. r._field == "example-field" and
    6. r.tag == "example-tag"
    7. )

Related articles

query select where