pyhton 调用es
# 连接Elasticsearch服务器 ---测试环境 es = Elasticsearch(["http://10.XX.0.XX:XXX"], http_auth=['elastic', 'XXXX^%$']) query_body = { "query": { "bool": { "must":[ {"terms": {"targetId": item_ids}}, # 查询多个值 # {"match": {"targetId": "108230347059905"}}, # 查询单个 {"match": {"templateId":"554578"}} ], "filter": [ { "range": { "operationDate": { "gte": "2024-01-18T21:00:00.000Z", "lte": "2024-01-18T21:30:59.000Z" } } } ] }, } }
res = es.search(index="sf_adManageOperaion_log-*",
body=query_body,
_source = ['targetName', 'targetId','operationDate','message', 'operationContent'],
size = 1000
)
print(res)
for hit in res["hits"]["hits"]:
print(hit["_source"])
# 参考
https://blog.csdn.net/u012206617/article/details/128470357
#-----------------------------------------------------
# 获取所有的索引
# indices = es.indices.get_alias().keys()
#
# # 打印所有的索引
# for index in indices:
# print(index)