【问题标题】:InfluxDB Flux - Filter where field matches valueInfluxDB Flux - 过滤字段匹配值的位置
【发布时间】:2021-01-29 11:10:25
【问题描述】:

我正在使用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(fn:(r) => r._measurement == "items" and r.itemType == "example") 替换 filter 函数不会返回任何结果,即使上面的 InfluxQL 查询在 InfluxDB CLI 中使用时确实返回数据。

【问题讨论】:

    标签: influxdb influxql


    【解决方案1】:

    如果 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)
    

    【讨论】:

      猜你喜欢
      • 2021-03-29
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2019-12-03
      • 2021-09-16
      • 1970-01-01
      相关资源
      最近更新 更多