python - 使用elasticsearch-py关闭与Elasticsearch集群的连接

标签 python python-3.x elasticsearch elasticsearch-py

我正在尝试使用elasticsearch-py在我的应用程序代码中关闭到我的Elasticsearch集群的连接。

目前,我正在使用:

es = Elasticsearch()
es.close()

但是,我得到了错误:
Traceback (most recent call last):
  File "tmp.py", line 45, in <module>
    es.close()
AttributeError: 'Elasticsearch' object has no attribute 'close'

我也没有在文档中看到任何关闭方法:

https://elasticsearch-py.readthedocs.io/en/master/api.html

任何帮助将不胜感激!提前致谢 :)

最佳答案

您可以使用 Transport.close 关闭传输:

es = Elasticsearch()
es.transport.close()

关于python - 使用elasticsearch-py关闭与Elasticsearch集群的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56417803/

相关文章:

python - 如何计算总和为给定值的倍数?

python - 在 Mac OS X 上将 Python3 与 CMake 链接起来

elasticsearch - 将Elasticsearch Bool查询与范围提升相结合

php - 将CURL命令转换为CURL php

elasticsearch - 在elasticsearch中搜索其值为NULL或任何特定值的字段

python - Seaborn tsplot 没有显示任何内容

python - 如何为 Dataframe 中的所有列绘制 Seaborn Distplots 矩阵

python - 如何让 matplotlib.pyplot 在 OSX 的虚拟环境中工作?

python - 在 Python 3 中使用带字节的 textwrap.dedent()

python-3.x - Pyspark orderBy 在对多列进行排序时给出不正确的结果