creimers
creimers

Reputation: 5303

influxdb query: specify or filter tag by regex

According to the docs, we can...

Use a regular expression to specify a tag with a value in the WHERE clause.

When I query my influxdb like this, I get the desired results.

> SELECT "field" FROM "measurement" WHERE tag = 19 😀

When replacing the where filtering by a regex, however, I get no results.

> SELECT "field" FROM "measurement" WHERE tag =~ /19/ 😕

Can someone tell me why that is?

Upvotes: 11

Views: 25496

Answers (2)

Anish
Anish

Reputation: 1960

Regex using Flux Query for InfluxDB 2.0.

src: https://docs.influxdata.com/influxdb/cloud/query-data/flux/regular-expressions/

The following example excludes records that do not have _percent in a field key.

from(bucket: "example-bucket")
|> range(start: -15m)
|> filter(fn:(r) => r._measurement == "mem" and r._field =~ /_percent/ )

Upvotes: 0

creimers
creimers

Reputation: 5303

Found the mistake myself...

I had both a field and a tag with the same key. So I was doing

> SELECT "filed_key" from "measurement" WHERE field_key =~ /val/

Now I have changed my schema so that keys across fields and tags are unique, and everything works as expected.

There's also a discussion about this phenomenon on github.

Upvotes: 10

Related Questions