# ES Connection object - Lifetime

**URL:** <https://discuss.elastic.co/t/es-connection-object-lifetime/20928>\
**Category:** Elasticsearch\
**Created:** [November 25, 2014, 2:39am UTC](https://discuss.elastic.co/t/es-connection-object-lifetime/20928 "2014-11-25T02:39:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ap1](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Ap1](https://discuss.elastic.co/u/Ap1)\
**Post date:** [November 25, 2014, 2:39am UTC](https://discuss.elastic.co/t/es-connection-object-lifetime/20928/1 "2014-11-25T02:39:28Z")

</div>

How long does the connection object stay open in ES ?

Eg. For Python

es = elasticsearch.Elasticsearch([  
{'host': 'localhost', 'port': 9200}  
])

I have a web service that keeps running on production. Do I need to check  
if the connection is open after x time ? say 24 hrs ?  
How can I set it to run all the time ?

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/56a244a0-d805-4c1c-a7b6-fa6b118404aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/56a244a0-d805-4c1c-a7b6-fa6b118404aa%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Honza\_Kral](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/honza_kral/32/876_2.png) [@Honza\_Kral](https://discuss.elastic.co/u/Honza_Kral)\
**Post date:** [November 25, 2014, 12:37pm UTC](https://discuss.elastic.co/t/es-connection-object-lifetime/20928/2 "2014-11-25T12:37:27Z")

</div>

Hi,

the connection is lazy so it will only be opened once you make a  
request - just instantiating a client like this will not create any  
connections.

Once a connection is created the python client will try to hold on to  
it as long as possible (it uses urllib3 to do the connection pooling  
itself) and reuse it. Even if it's closed you don't have to check and  
it will automatically reopen.

Hope this helps,  
Honza

On Tue, Nov 25, 2014 at 3:39 AM, Ap [usc90909@gmail.com](mailto:usc90909@gmail.com) wrote:

> How long does the connection object stay open in ES ?
> 
> Eg. For Python
> 
> es = elasticsearch.Elasticsearch([  
> {'host': 'localhost', 'port': 9200}  
> ])
> 
> I have a web service that keeps running on production. Do I need to check if  
> the connection is open after x time ? say 24 hrs ?  
> How can I set it to run all the time ?
> 
> Thanks.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/56a244a0-d805-4c1c-a7b6-fa6b118404aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/56a244a0-d805-4c1c-a7b6-fa6b118404aa%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CABfdDio%3DCmPrCboffmwNeebOO-1iZH28zY%3DW2sW-x0SBwGiVyQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CABfdDio%3DCmPrCboffmwNeebOO-1iZH28zY%3DW2sW-x0SBwGiVyQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:47am UTC](https://discuss.elastic.co/t/es-connection-object-lifetime/20928/3 "2017-07-06T00:47:45Z")

</div>


