Problem in connecting to Elasticsearch using Python script

Hello All,

I have a 3 node elastic cluster setup on EC2. I am trying to connect to my cluster and index some sample data using python script.

Below is my python script: -

from elasticsearch import Elasticsearch
print es

    "age": 27,
    "about": "Love to play cricket",
    "interests": ['sports','music'],

print e1

#storing e1 document in Elasticsearch
res = es.index(index='ep1',doc_type='employee',id=1,body=e1)
print res

I am executing the above python script on one of the EC2 which is part of Elasticsearch cluster.
But while executing the above script i am getting below error

<Elasticsearch([{'host': '', 'scheme': 'http', 'port': 9200}])>
{'interests': ['sports', 'music'], 'about': 'Love to play cricket', 'first_name': 'nitin', 'last_name': 'panwar', 'age': 27}
Traceback (most recent call last):
  File "", line 20, in <module>
    res = es.index(index='ep1',doc_type='employee',id=1,body=e1)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/", line 168, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/", line 411, in index
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/", line 413, in perform_request
    raise e
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f76a7aae7d0>: Failed to establish a new connection: [Errno -2] Name or service not known) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f76a7aae7d0>: Failed to establish a new connection: [Errno -2] Name or service not known)
````Preformatted text`

Please help me to resolve this connection issue


Please reformat your post, your use of code formatting for the entire thing makes the non-code sections very difficult to follow.

I have reformatted my post. Please let me know if its easily readable now.

The host parameter when you create the client seems to contain a full URL rather than a host name. Can you try replacing this with just the hostname or ip address?

It worked by putting only ip as a host name. Thanks Christian

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