下载python对应的elasticsearch依赖包
pip3 install elasticsearch==7.10.0
python操作elasticsearch代码
1 2 3 4 5 6 7
| from elasticsearch import Elasticsearch print("init ...") es = Elasticsearch([{'host':'XXXXXX','port':9200}], http_auth=('elastic', 'XXXXXX'))
countRes = es.count(index='yj_ip_pool') print(countRes)
|
查询效果
1 2 3 4 5
| gaolei:awesome-python3-webapp gaolei$ /usr/local/opt/python/bin/python3.7 /Users/gaolei/Documents/DemoProjects/awesome-python3-webapp/www/es_test.py init ... {'count': 20095400, '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0}} gaolei:awesome-python3-webapp gaolei$
|