这里主要使用了elasticsearch的接口
_delete_by_query
# 清理指定时间之前的数据
curl -X POST "http://localhost:9200/[索引名]/_delete_by_query?pretty&wait_for_completion=false" -H 'Content-Type: application/json' -d '
{
"query": {
"range": {
"[时间日期字段]": {
"lt": "2024-03-31 00:00:00"
}
}
}
}
'
此处在后台运行,响应结果示例:
{
"took" : 3686,
"timed_out" : false,
"total" : 117666,
"deleted" : 117666,
"batches" : 118,
"version_conflicts" : 0,
"noops" : 0,
"retries" : {
"bulk" : 0,
"search" : 0
},
"throttled_millis" : 0,
"requests_per_second" : -1.0,
"throttled_until_millis" : 0,
"failures" : [ ]
}
响应解释:
took: 表示整个操作的开始到结束的毫秒数。
timed_out: 请求处理过程中是否超时
total: 成功处理的doc数量
deleted: 成功删除的文档数。
batches: 通过查询删除的scroll响应数量。
version_conflicts: 根据查询删除时,版本冲突的数量。
noops: 暂没发现有什么作用,据悉是为了保持跟其他api结构一致
retries: search 操作和bulk操作的重试次数
throttled_millis: 因为requests_per_second而产生的睡眠时间
requests_per_second: 每秒处理的请求数
# 查看任务
curl -XGET "http://localhost:9200/_tasks?detailed=true&actions=*/delete/byquery&pretty"
# 优化所有的索引
curl -XPOST "http://localhost:9200/_forcemerge?only_expunge_deletes=true"