Query

Query Key Definitions

Every key MUST be String.t/0. Do not use atom/0.

fields

If empty list/0, FluxInfluxDB will retrieve all fields.

Otherwise, FluxInfluxDB will return all fields described, even if it does not exists (it will return with value null).

from

If empty String.t/0, FluxInfluxDB will not restrict the query to a lower boundary of time.

Otherwise, FluxInfluxDB will restrict the query based on value received.

limit

If 0, FluxInfluxDB will retrieve all data after offset.

Otherwise, FluxInfluxDB will retrieve n data after offset.

offset

If 0, FluxInfluxDB will retrieve without any offset.

Otherwise, FluxInfluxDB will retrieve after an offset of size n.

order_asc

If true, FluxInfluxDB will retrieve data with ascendent order (From oldest to latest).

Otherwise, FluxInfluxDB will retrieve data with descendant order (From latest to oldest).

to

If empty String.t/0, FluxInfluxDB will not restrict the query to a upper boundary of time.

Otherwise, FluxInfluxDB will restrict the query based on value received.

where

Restrict the query based on statements.

Using list/0, each element will be joined by an OR operator.

Using map/0, each element will be joined by an AND operator.

Each statement must contain the field name and the expected condition.

A condition can be a specific value, such as:

%{"name" => "John Doe"}

A condition can be one of multiple values, such as:

%{"age" => [18, 22, 30]}

A condition can also be composed based on InfluxDB by using a map/0 with c and v keys. c is the condition and v is the value.

Examples

Complete query with simple AND

%{
  "fields" => ["name", "age", "phone"],
  "where" => %{
    "country" => "United States",
    "name" => %{"c" => "=~", "v" => "Alderson"},
    "company" => ["evil corp", "allsafe"]
  },
  "from" => "now() - 100d",
  "to" => "now()",
  "order_asc" => true,
  "offset" => 20,
  "limit" => 5
}

Query with simple OR

%{
  "where" => [
    %{"job" => "Jedi"},
    %{"name" => "Darth Vader"}
  ]
}