Docs

v2.0

Execute queries

There are multiple ways to execute queries with InfluxDB. This guide covers the different options:

  1. Data Explorer
  2. Influx REPL
  3. Influx query command
  4. InfluxDB API

Data Explorer

Queries can be built, executed, and visualized in InfluxDB UI’s Data Explorer.

Data Explorer with Flux

Influx REPL

The influx repl command starts an interactive read-eval-print-loop (REPL) where you can write and execute Flux queries.

influx repl --org org-name

Note: ctrl-d will close the REPL.

Influx query command

You can pass queries to the influx query command as either a file or raw Flux via stdin.

Run a query from a file
influx query @/path/to/query.flux
Pass raw Flux via stdin pipe
influx query - # Return to open the pipe

data = from(bucket: "example-bucket") |> range(start: -10m) # ...
# ctrl-d to close the pipe and submit the query

InfluxDB API

Query InfluxDB through the /api/v2/query endpoint. Queried data is returned in annotated CSV format.

In your request, set the following:

  • Authorization header to Token + your authentication token.
  • accept header to application/csv
  • content-type header to application/vnd.flux

This allows you to POST the Flux query in plain text and receive the annotated CSV response.

Below is an example curl command that queries InfluxDB:

curl http://localhost:9999/api/v2/query -XPOST -sS \
-H 'Authorization: Token YOURAUTHTOKEN' \
-H 'accept:application/csv' \
-H 'content-type:application/vnd.flux' \
-d 'from(bucket:“test”)
      |> range(start:-1000h)
      |> group(columns:[“_measurement”], mode:“by”)
      |> sum()'
curl http://localhost:9999/api/v2/query -XPOST -sS -H 'Authorization: Token TOKENSTRINGHERE' -H 'accept:application/csv' -H 'content-type:application/vnd.flux' -d 'from(bucket:“test”) |> range(start:-1000h) |> group(columns:[“_measurement”], mode:“by”) |> sum()'

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