Elasticsearch ping() with Python is returning False

Viewed 14

Trying to ping to elasticsearch https://localhost:9200 from Python. es.ping() is returning False.

From browser I am able to connect to https://localhost:9200 with username and password (asked only for first time).

def connect_elasticsearch():
    es = None
    es = Elasticsearch(['https://localhost:9200'], basic_auth=('elastic', 'password'))
    print(es)
    if es.ping():
        print('Yupiee  Connected ')
    else:
        print('Awww it could not connect!')
    return es

es1 = connect_elasticsearch()

Output:

<Elasticsearch(['https://localhost:9200'])>
Awww it could not connect!
1 Answers

Tldr;

As per the documentation,

This API call can fail either at the transport layer (due to connection errors or timeouts) or from a non-2XX HTTP response (due to authentication or authorization issues).

Solution

To be able to go on, please use the line below

print(es.info())

This should help you understand what is going wrong.

I suspect the certificate are not trusted.

Related