influxdb如何把point中的多个field一起查出来
2021年8月29日 14:39
问题描述
influx查询包含了水平拆分、垂直拆分. 查询结果的每一条记录record,只对应一个field
写入一个point时包含多个field, 查询时如何将这几个field一起查出来呢?
写入示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | point := influxdb2.NewPoint( "history" , map[string]string{ "Version" : DedefaultVersion, "Name" : sh.Name, "Active" : fmt .Sprintf( "%v" , sh.Active), "PortIdx" : fmt .Sprintf( "%d" , sh.PortIdx), "Port" : fmt .Sprintf( "%v" , sh.Port), }, map[string]interface{}{ "MsgId" : fmt .Sprintf( "%d" , sh.MsgId), "Content" : sh.Content, }, time .Now(), ) |
* 查询
1 2 3 | from(bucket: "my-bucket" ) |> range(start: -10m) |> filter(fn: (r) => (r._measurement== "history" ) and (r.Name== "xxxx" ) ) |
用这个方法查询, 每个record只包含一个_field
解决方法: 分组
分组之后的record,会多一个table属性。table相同,则为一组。也就是一个point的field。
* 按写入时间分组
1 | |> group(columns: [ "_time" ]) |
* 增加id标签,按id分组
为每个point增加一个id标签, 然后按id分组