Where clause in Flux

Hi, how can I use a “where” clause with Flux? I just want to return all the data points from a measurement “where” a tag has the word “router1” in it.

My InfluxQL would be:
select * from measurementName where tagName =~ /router1/ and time >= now() - 1m limit 2

Trying to write the same thing with Flux.

Thanks,
Mo

Hi @mohsin106,

You can use the filter. In example :

from(bucket:"yourbucket/your_retention_policy")
  |> range(start:-1h)
  |> filter(fn: (r) =>
    r._measurement == "host" and
    r._field == "usage_system" and
    r.cpu == "cpu-total" #This is your tag filter
  )

Hi @NicolasDrapier

When I try that I get an error message in the explorer window:

My Query:

from(bucket: "bb_interfaces_test")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "interfaces")
  |> filter(fn: (r) => r._field == "in-octets")
  |> filter(fn: (r) => r.interface-name =~ /et/)  #This is my tag

Error Message:

@mohsin106 Dot notation doesn’t like the hyphen in your tag name. Use bracket notation:

//...
  |> filter(fn: (r) => r["interface-name"] =~ /et/)

@scott Thanks that was it!
I had a feeling it had something to do with the hyphen so I started renaming “interface-name” to “ifaceName”. After the rename my previous flux query worked as well.