在python中连接elasticsearch
原文地址:在python中连接elasticsearch – 无敌牛
欢迎参观我的个人博客:无敌牛 – 技术/著作/典籍/分享等
做一个记录,以后开发直接拷贝修改后使用即可。
代码如下
# -*- coding:utf-8 -*-
from elasticsearch import Elasticsearch
ES_USER="user"
ES_PASSWORD="password"
es = Elasticsearch(
["https://127.0.0.1:9200"],
basic_auth = (ES_USER, ES_PASSWORD),
max_retries = 5,
retry_on_timeout = True,
retry_on_status=[502, 503, 504],
verify_certs=False,
connections_per_node = 8,
)
if es.ping():
print("=======================================")
else :
print("error error error ")
indices = es.cat.indices(format="json", h=['index'])
print(indices)