Modify value in a table

Hi

I’m storing alarms from a machine in Influx and then visualizing them in Grafana. When the machine unexpectedly stops, the “Unknown” alarm is triggered.

I want to be able to change the cause of the alarm from “Unknown” to, for example, “No material”.

When I tried the following Flux query, the original value didn’t change. Instead, a new table was created with the new “Cause”.

from(bucket: "test")
  |> range(start: -10m, stop: now())
  |> filter(fn: (r) => r["_measurement"] == "Machine")
  |> filter(fn: (r) => r["_field"] == "Alarm")
  |> filter(fn: (r) => r["Cause"] == "Unknown")
  |> map(fn: (r) => ({ r with Cause: "No material" }))
  |> to(bucket: "test")

I also tried to change the _value for a point/row which worked. The original value changed and no new table was created. If I were able to do the same with the Cause column, I would be pleased.

from(bucket: "test")
  |> range(start: -10m, stop: now())
  |> filter(fn: (r) => r["_measurement"] == "Machine")
  |> filter(fn: (r) => r["_field"] == "Alarm")
  |> filter(fn: (r) => r["Cause"] == "Unknown")
  |> map(fn: (r) => ({ r with _value: false }))
  |> to(bucket: "test")

What I’m looking for is a way to change the strings in the “Cause” column without creating new tables or rows.

Hello @alexTingvalla,
You can’t upsert tag values.
To upsert in influxdb you need to be writing the same series with different field values. Different tag values will be interpreted as a new series and therefore you’ll always be writing these new data points.

1 Like

The only way to update that tag value is to write the new series and then delete the old.

Hello @Anaisdg ,

I see…
The best way to solve my problem may be to update the field values instead of tag values, or create new series just like you mentioned.

Thank you for helping me! I appreciate it.

I can´t seem to get it right

I have tried to update/modify the _field strings instead of the tags. I experiences the same problem as before. The values do not update, instead it seems like new tables are created.

A solution may be to have all of this data in one table, namely all the points have same value in the table column.

After my attempt to update field value

As seen in the picture, the “Unknown” is still visible when it should have been replaced with “No material”.

The query I’m using to unsuccessfully update the field values

from(bucket: "hej")
  |> range(start: -15m, stop: now())
  |> filter(fn: (r) => r["_measurement"] == "Alarms")
  |> filter(fn: (r) => r["_field"] == "Unknown")
  |> filter(fn: (r) => r["Machine"] == "Robot")
  |> map(fn: (r) => ({ r with _field: "No material" }))
  |> to(bucket: "hej")

Hello @alexTingvalla,
You can only update the field value no the field itself and expect an upsert. creating a new field No material is adding a new series so you wont replace the old one. To understand series better please read:

Or maybe even

I hope that helps.

You’ll have to delete those series you don’t want with the delete functionality

Hello,
Thanks, I will check out the links you shared.