Connection Timeout with Elasticsearch Connection Timeout with Elasticsearch python python

Connection Timeout with Elasticsearch


By default, the timeout value is set to 10 secs. If one wants to change the global timeout value, this can be achieved by setting the flag timeout=your-time while creating the object.

If you have already created the object without specifying the timeout value, then you can set the timeout value for particular request by using request_timeout=your-time flag in the query.

es.search(index="my_index",          doc_type="document",          body=get_req_body(),          request_timeout=30)


Try setting timeout in Elasticsearch initialization:

es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30)

You can even set retry_on_timeout to True and give the max_retries an optional number:

es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30, max_retries=10, retry_on_timeout=True)


The connection timed out problem could occur if you are using Amazon Elastic Search service.

es = Elasticsearch([{'host': 'xxxxxx.us-east-1.es.amazonaws.com', 'port': 443,  'use_ssl': True}])

The above python code where you override the default port from 9200 to 443 and setting the SSL to true will resolve the issue.

If no port is specified, it is trying to connect to the port 9200 in the specified host and fails after time out