删除数据
使用 influx
CLI 或 InfluxDB API /api/v2/delete
端点从 InfluxDB Bucket 中删除数据。
InfluxDB 2.7 支持按以下条件删除数据
- 时间范围
- 测量 (
_measurement
) - 标签
无法按字段删除数据
InfluxDB 2.7 不支持按字段删除数据。
一旦删除请求成功完成,删除的数据将不再可查询,但将保留在磁盘上,直到压缩服务运行。
使用 influx CLI 删除数据
使用 InfluxDB CLI 连接配置 提供您的 InfluxDB 主机、组织和 API 令牌。
使用
influx delete
命令 从 InfluxDB 中删除数据点。使用
--bucket
标志指定要从中删除数据的 Bucket。使用
--start
和--stop
标志定义要从中删除数据的时间范围。使用 RFC3339 时间戳。(可选) 使用
-p
、--predicate
标志包含一个 删除谓词,用于标识要删除的点。在没有 删除谓词 的情况下删除数据会删除指定 Bucket 中时间戳在指定的
start
和stop
时间之间的所有数据。
示例
删除特定测量中具有特定标签值的点
influx delete --bucket example-bucket \
--start '1970-01-01T00:00:00Z' \
--stop $(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--predicate '_measurement="example-measurement" AND exampleTag="exampleTagValue"'
删除指定时间范围内的所有点
influx delete --bucket example-bucket \
--start 2020-03-01T00:00:00Z \
--stop 2020-11-14T00:00:00Z
使用 API 删除数据
使用 InfluxDB API /api/v2/delete
端点 从 InfluxDB 中删除数据点。
POST http://localhost:8086/api/v2/delete
包括以下内容
- 请求方法:
POST
- 标头
- Authorization:
Token
模式,带有您的 InfluxDB API 令牌 - Content-type:
application/json
- Authorization:
- 查询参数
- 请求正文: 具有以下字段的 JSON 对象
* 必需
示例
删除特定测量中具有特定标签值的点
curl --request POST http://localhost:8086/api/v2/delete?org=example-org&bucket=example-bucket \
--header 'Authorization: Token YOUR_API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"start": "2020-03-01T00:00:00Z",
"stop": "2020-11-14T00:00:00Z",
"predicate": "_measurement=\"example-measurement\" AND exampleTag=\"exampleTagValue\""
}'
删除指定时间范围内的所有点
curl --request POST http://localhost:8086/api/v2/delete?org=example-org&bucket=example-bucket \
--header 'Authorization: Token YOUR_API_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"start": "2020-03-01T00:00:00Z",
"stop": "2020-11-14T00:00:00Z"
}'
有关更多信息,请参阅 /api/v2/delete
端点文档。
要删除 Bucket,请参阅 删除 Bucket。
此页面是否对您有帮助?
感谢您的反馈!