I want to get min and max time for given multiple fields.
I'm able to get min or max time using following influx query. I'm not sure if it is true or not but seems like working to me.
const fluxQuery = `from(bucket: "xxx")
|> range(start: 0)
|> filter(fn: (r) => r["_field"] =~ /^sensor1|sensor2$/) // targeting multiple fields
|> group(columns: ["_field"]) // don't know what is the use
|> keep(columns: ["_time","_field", "_value"]) // in result, I want to get time, field and value columns
|> min(column: "_time") ` // to get min value on time AND use max to get max time
Is the above query right?
As you can see above, I have to use either max or min individually. Is there a combined way to get min and max time together in a single query?
I have the following code written in Node.js to get data from influxDB 2.0:
const myQuery = async () => {
for await (const { values, tableMeta } of queryApi.iterateRows(fluxQuery)) {
const o = tableMeta.toObject(values);
console.log("field", o['_field'])
console.log("time", o['_time'])
console.log("value", o['_value'])
}
}
myQuery()
and it prints the following output:
field sensor1
time 2024-01-02T21:54:26.7Z
value 212259004416
field sensor2
time 2024-01-02T22:36:51.837Z
value 1000