Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete points with unwanted field values from InfluxDB measurement

Tags:

InfluxDB lets you delete points based on WHERE tag='value' conditions, but not by field value.

For example, if you have accidentally stored a measurement with a value of -1 in a series of positive floats (e.g. CPU utilization), DELETE FROM metrics WHERE cpu=-1 will return this error:

fields not supported in WHERE clause during deletion

like image 544
Dan Dascalescu Avatar asked Sep 25 '16 09:09

Dan Dascalescu


People also ask

How do I delete a field in InfluxDB?

Delete data using the influx CLIUse the influx delete command to delete points from InfluxDB. Use the --bucket flag to specify which bucket to delete data from. Use the --start and --stop flags to define the time range to delete data from. Use RFC3339 timestamps.

How do I delete measurements on InfluxDB?

Delete measurements with DROP MEASUREMENT The DROP MEASUREMENT query deletes all data and series from the specified measurement and deletes the measurement from the index. Note: DROP MEASUREMENT drops all data and series in the measurement. It does not drop the associated continuous queries.

What is difference between tag and field in InfluxDB?

Fields are a necessary entity of building the database which are “non-indexed” hence they get scanned for all values when queried. Tags on the other hand are not a necessary but indexed entities that make the queries more performant.

How do you query in InfluxDB?

To perform an InfluxQL query, send a GET request to the /query endpoint, set the URL parameter db as the target database, and set the URL parameter q as your query. You can also use a POST request by sending the same parameters either as URL parameters or as part of the body with application/x-www-form-urlencoded .


1 Answers

This is still (2015 - 2020) not possible in InfluxDB - see ticket 3210.

You could overwrite the point with some other values by inserting in the measurement a point with the same timestamp and tag set:

A point is uniquely identified by the measurement name, tag set, and timestamp. If you submit a new point with the same measurement, tag set, and timestamp as an existing point, the field set becomes the union of the old field set and the new field set, where any ties go to the new field set. This is the intended behavior.

Since you're not supposed to insert nulls, you'll probably want to repeat the values from the previous point(s).

You might think about inserting a point with the same timestamp, and setting a unique value for one of the tags, then running a delete against that tag:

DELETE FROM measurement WHERE some_existing_tag='deleteme' 

This won't work though. When you insert that second deleteme point, it has a different tag set due to the deleteme tag, so InfluxDB will create a new point for it. Then the DELETE command will delete it, but not the original point you wanted to delete.

like image 68
Dan Dascalescu Avatar answered Sep 29 '22 12:09

Dan Dascalescu