From 9bec8859f2ddbfaca40819d0400608f78f09193c Mon Sep 17 00:00:00 2001 From: oryx1729 <78848855+oryx1729@users.noreply.github.com> Date: Tue, 4 May 2021 15:03:19 +0200 Subject: [PATCH] Test ES connection only for the default user (#1028) --- haystack/document_store/elasticsearch.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/haystack/document_store/elasticsearch.py b/haystack/document_store/elasticsearch.py index e22e14e6c..8b93584ea 100644 --- a/haystack/document_store/elasticsearch.py +++ b/haystack/document_store/elasticsearch.py @@ -180,11 +180,17 @@ class ElasticsearchDocumentStore(BaseDocumentStore): scheme=scheme, ca_certs=ca_certs, verify_certs=verify_certs, timeout=timeout) - # Test connection + # Test connection try: - status = client.ping() - if not status: - raise ConnectionError(f"Initial connection to Elasticsearch failed. Make sure you run an Elasticsearch instance at `{hosts}` and that it has finished the initial ramp up (can take > 30s).") + # ping uses a HEAD request on the root URI. In some cases, the user might not have permissions for that, + # resulting in a HTTP Forbidden 403 response. + if username in ["", "elastic"]: + status = client.ping() + if not status: + raise ConnectionError( + f"Initial connection to Elasticsearch failed. Make sure you run an Elasticsearch instance " + f"at `{hosts}` and that it has finished the initial ramp up (can take > 30s)." + ) except Exception: raise ConnectionError( f"Initial connection to Elasticsearch failed. Make sure you run an Elasticsearch instance at `{hosts}` and that it has finished the initial ramp up (can take > 30s).")