haystack ElasticsearchDocumentStore无法连接Elasticsearch



我是ElasticSearch以及干草堆的新手,并遵循教程:利用现有的常见问题解答来初始化DocumentStore:

import os
import time
from haystack.document_stores import ElasticsearchDocumentStore
# Wait 30 seconds only to be sure Elasticsearch is ready before continuing
time.sleep(30)
# Get the host where Elasticsearch is running, default to localhost
host = os.environ.get("ELASTICSEARCH_HOST", "localhost")
document_store = ElasticsearchDocumentStore(
host=host,
username="",
password="",
index="document",
embedding_field="question_emb",
embedding_dim=384,
excluded_meta_data=["question_emb"],
similarity="cosine",
)

也试过简单的版本,如:

from haystack.document_stores import ElasticsearchDocumentStore
doc_store = ElasticsearchDocumentStore(
scheme="https",
host='localhost',
username='', password='',
index='test' 
)

但是都失败了

WARNING:elasticsearch:GET https://localhost:9200/ [status:N/A request:0.037s]
Traceback (most recent call last):
File "C:Usersdellanaconda3libsite-packagesurllib3connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:Usersdellanaconda3libsite-packagesurllib3connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:Usersdellanaconda3libsite-packagesurllib3connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:Usersdellanaconda3libsite-packagesurllib3connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "C:Usersdellanaconda3libsite-packagesurllib3utilssl_.py", line 386, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:Usersdellanaconda3libssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:Usersdellanaconda3libssl.py", line 1040, in _create
self.do_handshake()
File "C:Usersdellanaconda3libssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:Usersdellanaconda3libsite-packageselasticsearchconnectionhttp_urllib3.py", line 255, in perform_request
response = self.pool.urlopen(
File "C:Usersdellanaconda3libsite-packagesurllib3connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "C:Usersdellanaconda3libsite-packagesurllib3utilretry.py", line 386, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:Usersdellanaconda3libsite-packagesurllib3packagessix.py", line 734, in reraise
raise value.with_traceback(tb)
File "C:Usersdellanaconda3libsite-packagesurllib3connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:Usersdellanaconda3libsite-packagesurllib3connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:Usersdellanaconda3libsite-packagesurllib3connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:Usersdellanaconda3libsite-packagesurllib3connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "C:Usersdellanaconda3libsite-packagesurllib3utilssl_.py", line 386, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:Usersdellanaconda3libssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:Usersdellanaconda3libssl.py", line 1040, in _create
self.do_handshake()
File "C:Usersdellanaconda3libssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)
---------------------------------------------------------------------------
ConnectionError                           Traceback (most recent call last)
~anaconda3libsite-packageshaystackdocument_storeselasticsearch.py in _init_elastic_client(cls, host, port, username, password, api_key_id, api_key, aws4auth, scheme, ca_certs, verify_certs, timeout, use_system_proxy)
270                 if not status:
--> 271                     raise ConnectionError(
272                         f"Initial connection to Elasticsearch failed. Make sure you run an Elasticsearch instance "
ConnectionError: Initial connection to Elasticsearch failed. Make sure you run an Elasticsearch instance at `[{'host': 'localhost', 'port': 9200}]` and that it has finished the initial ramp up (can take > 30s).
During handling of the above exception, another exception occurred:
ConnectionError                           Traceback (most recent call last)
<ipython-input-30-40f9994332f1> in <module>
----> 1 doc_store = ElasticsearchDocumentStore(
2     scheme="https",
3     host='localhost',
4     username='elastic', password='do4-uzbyc4ZN2yUKBhtJ',
5     index='CS1302'
~anaconda3libsite-packageshaystacknodesbase.py in wrapper_exportable_to_yaml(self, *args, **kwargs)
46 
47         # Call the actuall __init__ function with all the arguments
---> 48         init_func(self, *args, **kwargs)
49 
50     return wrapper_exportable_to_yaml
~anaconda3libsite-packageshaystackdocument_storeselasticsearch.py in __init__(self, host, port, username, password, api_key_id, api_key, aws4auth, index, label_index, search_fields, content_field, name_field, embedding_field, embedding_dim, custom_mapping, excluded_meta_data, analyzer, scheme, ca_certs, verify_certs, recreate_index, create_index, refresh_type, similarity, timeout, return_embedding, duplicate_documents, index_type, scroll, skip_missing_embeddings, synonyms, synonym_type, use_system_proxy)
141 
142         # Base constructor might need the client to be ready, create it first
--> 143         client = self._init_elastic_client(
144             host=host,
145             port=port,
~anaconda3libsite-packageshaystackdocument_storeselasticsearch.py in _init_elastic_client(cls, host, port, username, password, api_key_id, api_key, aws4auth, scheme, ca_certs, verify_certs, timeout, use_system_proxy)
274                     )
275         except Exception:
--> 276             raise ConnectionError(
277                 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)."
278             )
ConnectionError: Initial connection to Elasticsearch failed. Make sure you run an Elasticsearch instance at `[{'host': 'localhost', 'port': 9200}]` and that it has finished the initial ramp up (can take > 30s).

我使用windows 10, elasticsearch版本是8.6(最新),我不使用docker。任何帮助都是感激的!(ps.我已经看到了帖子Haystack's ElasticsearchDocumentStore()不能连接运行的ElasticSearch容器,但仍然没有关于如何做的线索。)

到目前为止(2023年1月),Haystack还不支持elasticsearch version 8。我建议您使用版本7。您可以关注以下GitHub问题,其中跟踪了对版本8的支持:https://github.com/deepset-ai/haystack/issues/2810

我没有找到原始问题的直接解决方案,但我试图使用docker,一切都很好,elasticsearch版本为7.9.2。希望能帮助到有同样问题的人。

相关内容

  • 没有找到相关文章

最新更新