You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
846 B
Python
33 lines
846 B
Python
# 输出查询结果])
|
|
|
|
from datetime import datetime
|
|
from elasticsearch import Elasticsearch
|
|
|
|
# 连接到 Elasticsearch
|
|
client = Elasticsearch("http://localhost:9209", basic_auth=("elastic", "changeme"))
|
|
|
|
start_date = datetime(2024, 1, 1) # 开始时间
|
|
end_date = datetime(2024, 12, 31) # 结束时间
|
|
|
|
# 构建查询体
|
|
query = {
|
|
"query": {
|
|
"range": {
|
|
"@timestamp": {
|
|
"gte": start_date.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
"lte": end_date.strftime("%Y-%m-%dT%H:%M:%S")
|
|
}
|
|
}
|
|
},
|
|
"size": 10000
|
|
}
|
|
|
|
# 执行查询操作
|
|
response = client.search(index="tp-log", body=query)
|
|
|
|
# 打印结果
|
|
print("Found {} documents:".format(response['hits']['total']['value']))
|
|
result = client.delete_by_query(index="tp-log", body=query)
|
|
|
|
# 打印删除结果
|
|
print("Deleted:", result) |