How do I downsample data using multiple operations within the same bucket (in Influxdb 2.0)?

So I want to downsample my data by taking the min, max and mean of the data every hour and storing it in a bucket. I’m following the below link, which works for one operation, but not all three.

The issue is that when using the method in the link, all of the measurement names are exactly the same in the output. I instead need the new measurement names to be “temperature_mean”, “temperature_min”, “temperature_max” etc. Or I guess the measurements can be named the same thing, just “temperature” but then they need a mean tag, a min tag and a max tag. I can’t figure out how to do this.

I’ve tried using from(), to(), aggregateWindow(), rename()…nothing I do seems to work.

Just to summarize:

option task = {name: "downsample_task", every: 1h}

data = from(bucket: "some_bucket")
	|> range(start: -duration(v: int(v: task.every) * 2))
	|> filter(fn: (r) =>
		(r["_measurement"] == "some_data" or r["_measurement"] == "some_other_data"))

data
	|> aggregateWindow(fn: mean, every: 1h)
	|> to(bucket: "some_bucket_downsampled", org: "anemail@gmail.com")

The above code does work – it calculates the mean every 1 hour and puts it into a new bucket. The issue is that I also want to get the min and max and put it in the same bucket. How do I do this? The main problem I’m facing is that the output isn’t prefixed or postfixed with _mean, so every downsampled measurement has the same name.

Hello @Zane470,
You can specifying the measurement in the to() function. You would just need to write dummy data to that bucket first to initialize the measurement. You can construct a table and write it to the bucket first after adding a measurement.
https://www.influxdata.com/blog/tldr-tech-tips-how-to-construct-a-table-with-flux/

Then you can write the outputs do those measurements:

|> to(bucket: "some_bucket_downsampled", _measurement: "mean")

Alternatively you can create a task for each downsampled aggregation.

Also, please check out these resources as well:


https://www.influxdata.com/blog/tldr-tech-tips-how-to-extract-values-visualize-scalars-and-perform-custom-aggregations-with-flux-and-influxdb/