Search code examples
fluxinfluxdb-2

Influxdb2 Merge one measurement into another using flux


I set up influxdb2 to collect data into a measurement "meas0". Now I imported historic data using the line protocol, unfortunately I did a mistake with the target measurement and it went into a second series "meas1". The structure and names regarding the fields and tags are the same.

I found a solution on stackoverflox for influxdb1 using fluxQL. I understand that this is not available for fresh influxdb2 installations!?

So can someone show me how to merge "meas1" into "meas0" and get rid of "meas0"?


Solution

  • I found the following solution here: https://community.influxdata.com/t/how-to-copy-data-between-measurements/22582/4

    from(bucket: "example-bucket")
        |> range(start: 2021-11-21T00:00:00Z, stop: 2021-11-22T00:00:00Z)
        |> filter(fn: (r) => r._measurement == "meas0")
        |> set(key: "_measurement", value: "meas1")
        |> to(bucket: "example-bucket")
    

    There is also a way using map but I cannot find the reference aghain. Finally, to delete a whole measurement on can use "influx delete --bucket --start --stop --predicate '_measurement="meas0"'