//influxdb初始时获取的token
String token = "11111111";
InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://localhost:8086", token);
DeleteApi deleteApi = influxDBClient.getDeleteApi();
try {
//时区为北京则ofHours(8)
OffsetDateTime start = OffsetDateTime.of(2023,11,06,0,0,0,0, ZoneOffset.ofHours(8));
OffsetDateTime stop = OffsetDateTime.of(2023,11,06,23,59,59,59, ZoneOffset.ofHours(8));
//根据需求填写第三个参数,用于指定删除的数据条件
deleteApi.delete(start, stop, "_measurement=\"你的measurement\" and tag的key=\"tag的value\"", "bucket名", "org名");
} catch (InfluxException ie) {
System.out.println("InfluxException: " + ie);
}
influxDBClient.close();
记得在pom添加依赖:
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.21</version>
</dependency>