title |
description |
aliases |
menu |
weight |
related |
flux/v0.x/tags |
introduced |
contains() function |
The `contains()` function tests whether a value is a member of a set. |
/influxdb/v2.0/reference/flux/functions/built-in/tests/contains/ |
/influxdb/v2.0/reference/flux/stdlib/built-in/tests/contains/ |
/influxdb/cloud/reference/flux/stdlib/built-in/tests/contains/ |
|
flux_0_x_ref |
name |
parent |
contains |
universe |
|
|
102 |
/flux/v0.x/data-types/composite/array/ |
|
|
0.19.0 |
The contains()
function tests whether a value is a member of a set.
If the value is a member of the set, the function returns true
.
If the value is not a member of the set, the functions returns false
.
contains(
value: 1,
set: [1,2,3],
)
Parameters
value
Value to search for.
set
Set of values to search in.
Examples
Filter on a set of specific fields
import "influxdata/influxdb/sample"
fields = ["temperature", "humidity"]
sample.data(set: "airSensor")
|> range(start: -30m)
|> filter(fn: (r) => contains(value: r._field, set: fields))
{{% expand "View example input and output" %}}
{{< flex >}}
{{% flex-content %}}
Example input data
_time |
_field |
_value |
2020-01-01T00:00:00Z |
temperature |
74.1 |
2020-01-01T00:01:00Z |
temperature |
73.9 |
2020-01-01T00:02:00Z |
temperature |
74.0 |
2020-01-01T00:03:00Z |
temperature |
74.2 |
_time |
_field |
_value |
2020-01-01T00:00:00Z |
humidity |
35.5 |
2020-01-01T00:01:00Z |
humidity |
35.4 |
2020-01-01T00:02:00Z |
humidity |
35.5 |
2020-01-01T00:03:00Z |
humidity |
35.6 |
_time |
_field |
_value |
2020-01-01T00:00:00Z |
co |
0.65 |
2020-01-01T00:01:00Z |
co |
0.66 |
2020-01-01T00:02:00Z |
co |
0.66 |
2020-01-01T00:03:00Z |
co |
0.67 |
{{% /flex-content %}}
{{% flex-content %}}
Example output data
_time |
_field |
_value |
2020-01-01T00:00:00Z |
temperature |
74.1 |
2020-01-01T00:01:00Z |
temperature |
73.9 |
2020-01-01T00:02:00Z |
temperature |
74.0 |
2020-01-01T00:03:00Z |
temperature |
74.2 |
_time |
_field |
_value |
2020-01-01T00:00:00Z |
humidity |
35.5 |
2020-01-01T00:01:00Z |
humidity |
35.4 |
2020-01-01T00:02:00Z |
humidity |
35.5 |
2020-01-01T00:03:00Z |
humidity |
35.6 |
{{% /flex-content %}}
{{< /flex >}}
{{% /expand %}}