I have a flux query that has several 'or' conditions in a filter function. It's something like this.
from(bucket: "my_buck")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "my_measurement")
|> filter(fn: (r) => r["idDispositivo"] == "155" or r["idDispositivo"] == "150")
|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
|> yield(name: "mean")
The example has only one 'or' but in the real query there can be several and the query would also be created dynamically. Is there a way to change
|> filter(fn: (r) => r["idDispositivo"] == "155" or r["idDispositivo"] == "150")
for something like
|> filter(fn: (r) => r["idDispositivo"] in ["155", "150"])
I know that this syntax is not correct, but ask if there is something similar that allows me to make the dynamic query easier without having to use so many 'or'
Note: I'm use the influxDB version 1.8
Thanks in advance
There is contains function in Flux that you could use. It will likely not perform as good as using or
or regexp.
from(bucket: "my_buck")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "my_measurement")
|> filter(fn: (r) => contains(value: r["idDispositivo"], set: ["155", "150"]))