Update record using influxdb-java client

I am trying to update a record (only the field values) using influxdb java client.
Specifically, I am using InfluxDBMapper to store the queried result, I update the POJO with new field values and build the PointBuilder as below:
final Builder b = Point.measurementByPOJO(reqInProgress.getClass()).addFieldsFromPOJO(reqInProgress);

I then use the influx.write() to send it to the DB. Batching is enabled. However I get 400 error and the values are not updated in the DB.

Is this not the right way to update values?

I think I found the reason. My DBs are with precision of Milliseconds. I have set the TimeUnit correctly for the POJO too. However when I Build the Point as above, it does not take into consideration the TimeUnit set by me and defaults to Nanoseconds.
This is probably the reason it fails.

I changed to below lines but it still does not change the time unit:

final long time = reqInProgress.getTime().getLong(ChronoField.MILLI_OF_SECOND);
final Builder b = Point.measurementByPOJO(reqInProgress.getClass()).addFieldsFromPOJO(reqInProgress).time(time, TimeUnit.MILLISECONDS);

Hello @mns,
What version of influx and client are you using?

Hi @Anaisdg my influx DB version is 1.7.8 and influxdb-java client version is 2.15

So I fixed my problem. Seems like using write is not the way to go when using influxDBMapper and instead influxDBMapper.save() should be used.
The reason being when write is used, time is added as a field in the line protocol and this is invalid in influxDB.

IMHO the client library should take care of converting the time appropriately especially if we annotate it as a time column.

Also, save seems like an update by default.

1 Like