Documentation

Query InfluxDB with Flux

This guide walks through the basics of using Flux to query data from InfluxDB. Every Flux query needs the following:

  1. A data source
  2. A time range
  3. Data filters

1. Define your data source

Flux’s from() function defines an InfluxDB data source. It requires a bucket parameter. The following examples use example-bucket as the bucket name.

from(bucket:"example-bucket")

2. Specify a time range

Flux requires a time range when querying time series data. “Unbounded” queries are very resource-intensive and as a protective measure, Flux will not query the database without a specified range.

Use the pipe-forward operator (|>) to pipe data from your data source into range(), which specifies a time range for your query. It accepts two parameters: start and stop. Start and stop values can be relative using negative durations or absolute using timestamps.

Example relative time ranges
// Relative time range with start only. Stop defaults to now.
from(bucket:"example-bucket")
    |> range(start: -1h)

// Relative time range with start and stop
from(bucket:"example-bucket")
    |> range(start: -1h, stop: -10m)

Relative ranges are relative to “now.”

Example absolute time range
from(bucket:"example-bucket")
    |> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-01T12:00:00Z)

Use the following:

For this guide, use the relative time range, -15m, to limit query results to data from the last 15 minutes:

from(bucket:"example-bucket")
    |> range(start: -15m)

3. Filter your data

Pass your ranged data into filter() to narrow results based on data attributes or columns. filter() has one parameter, fn, which expects a predicate function evaluates rows by column values.

filter() iterates over every input row and structures row data as a Flux record. The record is passed into the predicate function as r where it is evaluated using predicate expressions.

Rows that evaluate to false are dropped from the output data. Rows that evaluate to true persist in the output data.

// Pattern
(r) => (r.recordProperty comparisonOperator comparisonExpression)

// Example with single filter
(r) => (r._measurement == "cpu")

// Example with multiple filters
(r) => (r._measurement == "cpu" and r._field != "usage_system")

Use the following:

For this example, filter by the cpu measurement, usage_system field, and cpu-total tag value:

from(bucket: "example-bucket")
    |> range(start: -15m)
    |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total")

4. Yield your queried data

yield() outputs the result of the query.

from(bucket: "example-bucket")
    |> range(start: -15m)
    |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total")
    |> yield()

Flux automatically assumes a yield() function at the end of each script to output and visualize the data. Explicitly calling yield() is only necessary when including multiple queries in the same Flux query. Each set of returned data needs to be named using the yield() function.

Congratulations!

You have now queried data from InfluxDB using Flux.

The query shown here is a basic example. Flux queries can be extended in many ways to form powerful scripts.


Was this page helpful?

Thank you for your feedback!


New in InfluxDB 3.5

Key enhancements in InfluxDB 3.5 and the InfluxDB 3 Explorer 1.3.

See the Blog Post

InfluxDB 3.5 is now available for both Core and Enterprise, introducing custom plugin repository support, enhanced operational visibility with queryable CLI parameters and manual node management, stronger security controls, and general performance improvements.

InfluxDB 3 Explorer 1.3 brings powerful new capabilities including Dashboards (beta) for saving and organizing your favorite queries, and cache querying for instant access to Last Value and Distinct Value caches—making Explorer a more comprehensive workspace for time series monitoring and analysis.

For more information, check out:

InfluxDB Docker latest tag changing to InfluxDB 3 Core

On November 3, 2025, the latest tag for InfluxDB Docker images will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments.

If using Docker to install and run InfluxDB, the latest tag will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments. For example, if using Docker to run InfluxDB v2, replace the latest version tag with a specific version tag in your Docker pull command–for example:

docker pull influxdb:2

InfluxDB Cloud powered by TSM