Filter with part of tage name

Hi, i want to filter tags with “dmp” in the name without selecting the tag one by one. I tried the regexp solution but i can’t make it work (Filter with part of tag name).

How do i write the filter in the picture?

Hello @bmenard,
What error are you getting?
Can you share your tag keys here so I can try to reproduce?
Thank you.

@bmenard,
You might also want to try the contains() function like:
https://docs.influxdata.com/flux/v0.x/stdlib/universe/contains/

tagsContain =  ["100","101","102","103"] 

from(bucket: "airsensor")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "airSensors")
  |> filter(fn: (r) => r["_field"] == "co")
  |> filter(fn: (r) => contains(value: r.sensor_id, set: tagsContain))
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Where my tags are “TLM100”,“TLM101”,“TLM102”,“TLM103”
Or for you something like:

tagsContain =  ["dmp"] 

from(bucket: "mybucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "048_STEM")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["room_system"] == "AHU16")
  |> filter(fn: (r) => contains(value: r.sensor, set: tagsContain))

Let me know if that works for you.

I got no error, just no data. I tried your solution but got no data also.

Here’s the original query:
from(bucket: “Bacnet_Network”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “048_STEM”)
|> filter(fn: (r) => r[“room_system”] == “AHU16”)
|> filter(fn: (r) => r[“sensor”] == “470107_AI_4_STEM_TUE1_02_DMP_FBK” or r[“sensor”] == “470201_AO_5_STEM_TUE1_30_DMP_MOD” or r[“sensor”] == “470214_AO_1_STEM_TUE1_32_DMP_MOD” or r[“sensor”] == “470216_AO_1_STEM_TUE1_27_DMP_MOD” or r[“sensor”] == “470418_AO_1_STEM_TUE1_26_DMP_MOD” or r[“sensor”] == “470426_AO_5_STEM_TUE1_18_DMP_MOD”)
|> filter(fn: (r) => r["_field"] == “value”)
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> group()
|> mean(column: “_value”)

Hello @bmenard,
silly question, but did you try with capital letters? are you sure you have data in that time range? what happens if you increase the range?

Yes I did try capital letters but same result. I got near 2 days of data. I play with range but got no Results. Here’s the original query in csv if it can help.

Hello @bmenard,
What version are you using?

Hello @Anaisdg :joy:(20 characters min is annoying)
I use version 2.0.8
I also tried on 2.0.5 but same result

Hello @bmenard,
yes agreed can you please try using regex again?:

import "array"

data = array.from(rows: [{_time: now(), _value: 1.0, sensor: "470107_AI_4_STEM_TUE1_02_DMP_FBK"},
{_time: now(), _value: 1.0, sensor: "470201_AO_5_STEM_TUE1_30_DMP_MOD"}
{_time: now(), _value: 1.0, sensor: "470214_AO_1_STEM_TUE1_32_DMP_MOD"},
{_time: now(), _value: 1.0, sensor: "470216_AO_1_STEM_TUE1_27_DMP_MOD"},
{_time: now(), _value: 1.0, sensor: "470418_AO_1_STEM_TUE1_26_DMP_MOD"},
{_time: now(), _value: 1.0, sensor: "470426_AO_5_STEM_TUE1_18_DMP_MOD"}
])
// |> yield(name: "data")


data 
|> filter(fn: (r) => r.sensor =~ /DMP/)
|> yield(name: "contains")

It worked for me on your tags.

Again @Anaisdg, thx you so much. you rock! :metal:. I don’t know what i wrote when i tried the regex but now it’s working.

Have a good weekend!

1 Like