How to check if a specific tag exists in a measurement using flux language? My influxdb version is 2.0.
Asked
Active
Viewed 1,763 times
6
-
Could you please post your efforts in your question(what you tried) that's highly encouraged on SO, thank you. – RavinderSingh13 May 02 '21 at 16:25
-
I have the same question too, so i might expand it if this is ok, rather than asking another... – David van rijn May 24 '21 at 10:59
-
nvm. I found out the answer while rubber duck debugging ;) – David van rijn May 24 '21 at 11:09
2 Answers
3
simple you need to add a filter for the tag name you need to filter to your flux query. let's say the tag name is "tag_name":
|> filter(fn: (r) => exists r.tag_name)
this will filter any undefined or "unset" tag.

Hany Zekry
- 31
- 2
2
(answering for my usecase, since no details were provided)
TL;DR: use the exists operator.
Imagine a dataset which has this old tag, which we don't care about anymore, and we want to filter out those records when archiving:
option task = {
name: "15min_archive",
every: 1w,
}
from(bucket: "mybucket")
|> range(start: - duration(v: int(v: task.every) * 2))
// this:
|> filter(fn: (r) => (exists r["stupidOldTag"] ) == false )
|> aggregateWindow(every: 15m, fn: mean)
// ...
note: the ==false
because not
is apparently not a thing yet.

David van rijn
- 2,108
- 9
- 21