I recently added a global tag to all my Telegraf instances to be able to determine which data is sent from which instance. I use one Telegraf instance per device being polled, so I set the key of the global tag to “device” with the respective device as value. Now I downloaded the already recorded data, added the “device” tag and wrote the data back to the database. Next I wanted to delete the data that does not have a “device” tag. Unfortunately I only found in the documentation how to delete data due to existing tags, but not how to delete data due to non-existing tags. I found out that Flux has this ability, but I couldn’t find any way to use this method with the CLI or the API to delete the data. If I define a predicate, which is too loose, I would delete more data than desired. Is there a way to define a predicate which selects all data with - for example - a specific “name” tag AND no “device” tag?
1 Like
I also have this question! Perhaps an example will help. I have data with two tags, “sensor” and “units”. I want to delete any points without a “units” tag.
I can find this data to delete via filter():
from(bucket: "iotawatt")
|> range(start: start, stop: stop)
|> filter(fn: (r) => not exists r.units
This returns:
_value _time sensor
3761.39 2023-07-21T04:50:00.000Z Production
4902.29 2023-07-21T04:51:00.000Z Production
I can delete all points for sensor==“Production” data like so:
influx delete -p 'sensor=="Production"' --bucket "iotawatt" --start 2020-06-27T00:00:00+10:00 --stop 2023-09-01T00:00:00+10:00 --org myorg
But I only want to delete data without a Units tag.
How can I do that?
Thanks!
ps. I’m actually using the python client, but it’s just an interface to the same API and as the CLI.
pps. The related problem I’m trying to resolve via this delete is duplicate(?) points.