我在Python中运行以下代码:es = Elasticsearch([{'host': 'localhost', 'port': 9200}]).ping()
print (es)
if es:
r = requests.get('http://localhost:9200')
es.indices.delete(index='test_twitter', ignore=[400, 404])
connected = True
print('Connected to ES..')
else:
print('Not connected to ES...')
当Elasticsearch运行时,ping没有问题。问题是,当ES未运行时,ping()在以下所示的回溯错误打印后返回FALSE:
^{pr2}$
即使我尝试了以下方法,也不起作用:from elasticsearch.exceptions import ConnectionError
try:
es = Elasticsearch([{'host': 'localhost', 'port': 9200}]).ping()
except ConnectionRefusedError:
print ('Connection Errrorrr!')
print (es)
我希望ping()返回false,但不打印错误日志,以及如何实现这一点?在
完整的is代码如下