3

我正在将InfluxDBGrafana一起使用,并且我items使用一些标签和一个名为itemType. 我需要过滤itemType特定字符串的行。以下 InfluxQL 查询正是我需要的:

SELECT * FROM "items" WHERE "itemType" = 'example'

我怎样才能在Flux中做同样的事情?

我目前有以下查询,除了按字段过滤之外,它执行所有操作:

from(bucket: "dbname/autogen")
    |> range(start: 2020-10-12T01:56:34Z, stop: 2020-10-12T02:54:10Z)
    |> filter(fn:(r) => r._measurement == "items")
    |> aggregateWindow(every: 5m, fn: count)

但是将filter函数替换为filter(fn:(r) => r._measurement == "items" and r.itemType == "example")不返回任何结果,即使上面的 InfluxQL 查询在 InfluxDB CLI 中使用时确实返回数据。

4

1 回答 1

4

但是,如果itemType是标签,则您指定的通量查询将起作用,因为它是一个字段,使查询起作用的方法之一是在字段名称及其值上设置条件,如下所示:

from(bucket: "dbname/autogen")
    |> range(start: 2020-10-12T01:56:34Z, stop: 2020-10-12T02:54:10Z)
    |> filter(fn:(r) => r._measurement == "items" and r._field == "itemType" and r._value == "example")
    |> aggregateWindow(every: 5m, fn: count)
于 2020-10-16T22:40:38.730 回答