# Will Elasticsearch automatically load balance a two node cluser

**URL:** https://discuss.elastic.co/t/will-elasticsearch-automatically-load-balance-a-two-node-cluser/204956
**Category:** Elasticsearch
**Created:** [October 23, 2019, 8:19pm UTC](https://discuss.elastic.co/t/will-elasticsearch-automatically-load-balance-a-two-node-cluser/204956 "2019-10-23T20:19:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jtgajda](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jtgajda](https://discuss.elastic.co/u/jtgajda)
#### Post date: [October 23, 2019, 8:19pm UTC](https://discuss.elastic.co/t/will-elasticsearch-automatically-load-balance-a-two-node-cluser/204956/1 "2019-10-23T20:19:09Z")

</div>

I have a two node cluster. I currently connect to the master node using the Python Elasticsearch client.  
Will python automatically distibute the query traffice between the two nodes or do I need to take special actions?  
I did some research and it was suggested to accompish this as follows:  
es = Elasticsearch(["135.109.238.70", "135.109.238.66"],  
sniff\_on\_start=True,  
sniff\_on\_connection\_fail=True,  
sniffer\_timeout=60  
)  
However, when I add the sniff\_on\_start=True line, the python script fails with the following message.  
Traceback (most recent call last):  
File "./ts.py", line 22, in   
res = es.search(index="mcdocs", body={"from": 0, "size": 10, "\_source": {"excludes": ["content"]}, "query": {"match": {"content": "5g planning installation"}}})  
File "/usr/local/lib/python3.7/site-packages/elasticsearch/client/utils.py", line 84, in \_wrapped  
return func(\*args, params=params, \*\*kwargs)  
File "/usr/local/lib/python3.7/site-packages/elasticsearch/client/ **init**.py", line 819, in search  
"GET", \_make\_path(index, "\_search"), params=params, body=body  
File "/usr/local/lib/python3.7/site-packages/elasticsearch/transport.py", line 350, in perform\_request  
timeout=timeout,  
File "/usr/local/lib/python3.7/site-packages/elasticsearch/connection/http\_urllib3.py", line 245, in perform\_request  
raise ConnectionError("N/A", str(e), e)  
elasticsearch.exceptions.ConnectionError: ConnectionError(\<urllib3.connection.HTTPConnection object at 0x7f775ea76198\>: Failed to establish a new connection: [Errno -2] Name or service not known) caused by: NewConnectionError(\<urllib3.connection.HTTPConnection object at 0x7f775ea76198\>: Failed to establish a new connection: [Errno -2] Name or service not known)

If I remove the sniff\_on\_start=True or set it to False, the connection and query are successful. Will Elasticsearch load balance without the sniff\_on\_start or are there any other suggestions?  
Also, how can I tell if queries/traffic are actually being balanced between the two nodes. I am not seeing entries for individual queries.  
Thank you for any help with this!

---

<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: [November 20, 2019, 8:19pm UTC](https://discuss.elastic.co/t/will-elasticsearch-automatically-load-balance-a-two-node-cluser/204956/2 "2019-11-20T20:19:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
