Search code examples
pythonpython-3.xelasticsearchelasticsearch-py

Closing connections to an elasticsearch cluster using elasticsearch-py


I'm trying to close a connection to my elasticsearch cluster in my application code using elasticsearch-py.

Currently, I'm using:

es = Elasticsearch()
es.close()

But, I'm getting the error:

Traceback (most recent call last):
  File "tmp.py", line 45, in <module>
    es.close()
AttributeError: 'Elasticsearch' object has no attribute 'close'

I haven't seen any close methods in the documentation either:

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

Any help would be greatly appreciated! Thanks in advance :)


Solution

  • You can close the transport with Transport.close:

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