How to delete values based on non-existence of a tag

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.

1 Like

Old topic, but let me document a solution I just used.

I had a series with a missing tag and reinserted them with the tag. This created a problem with the increase() function in my case.

The way you can remove data that does not contain a tag is a bit cumbersome but possible.
Since the delete function only works with measurementname and tags you can use this to minimize the amount of data you need to export.

  1. Export the data you need to keep using CLI wit flux query.
    In my case export all measurements from EnergyMeters without the engunit tag.
"c:\Program Files\influxdb\influx.exe" query "from(bucketID: \"8b63d7f8570aaab6\") |> range(start: 2026-01-29T11:00:00Z, stop: 2026-01-29T17:00:00Z) |> filter(fn: (r) => r._measurement == \"EnergyMeter\") |> filter(fn: (r) => exists r.engunit)" --raw > c:\EnergyMeters.csv
  1. Convert it to a *.lp-file using a dryrun (might not be necessary, I had this already written down somewhere, reading the docs now it seems to be possible to import a csv directly).
"c:\Program Files\influxdb\influx.exe" write dryrun --bucket my-temp-bucket --format csv --file c:\EnergyMeters.csv> c:\EnergyMeters.lp
  1. Delete all data in the timeframe while specifying the same filter used in the export query.
"c:\Program Files\influxdb\influx.exe" delete --bucket-id 8b63d7f8570aaab6 --predicate "_measurement=\"EnergyMeter\"" --start 2026-01-29T11:00:00Z --stop 2026-01-29T17:00:00Z
  1. Reimport the correct data
"c:\Program Files\influxdb\influx.exe" write --bucket-id 8b63d7f8570aaab6 --file c:\EnergyMeters.lp

A hughe flaw of influxdb in my opinion is that you can’t edit the metadata that makes up a series. This makes simple things like adding a tag to a measurement verry difficult.

Same issue:
Delete measurements without specified tag

2 Likes