I have the following error:
elastic_transport.ConnectionTimeout: Connection timeout caused by:
ConnectionTimeout(Connection timeout caused by:
ReadTimeoutError(HTTPConnectionPool(host='localhost', port=9200):
Read timed out. (read timeout=9.999005171936005)))
from elasticsearch import Elasticsearch
import os
ELASTIC_PASSWORD = os.environ.get('ELASTIC_PASSWORD')
client = Elasticsearch('http://localhost:9200', basic_auth=("elastic", ELASTIC_PASSWORD), max_retries=3, retry_on_timeout=True)
doc = {
'text': 'Interesting content',
}
client.ping() # returns True!!
# the program reports error
client.indices.create(index="test-index", timeout="30s")
Solutions I have tried:
- increasing timeout
- add localhost to config/elasticsearch.yml
- use the unauthenticated version, i.e.:
client = Elasticsearch('http://localhost:9200')
- use https (would produce connection error)
Also, note that I have been able to create the index once when I first installed Elasticsearch python client. It failed the second and third time I ran the script. Another behavior I observed was that http://localhost:9200 is always up even if I closed the program...
Installation:
- Elasticsearch - I wget and un-tar it
- python client: python -m pip install elasticsearch
Self-answer: I did not work it through with local Elasticsearch client, but cloud client seems to work fine for me: