Установлено приложение на flask. Хочу подключить Elasticsearch для поиска данных. Установил elastic 8.14 в докере.
pip install elasticsearch
тоже версия 8.14
Тестирую в flask shell:
>>> from elasticsearch import Elasticsearch
>>> es = Elasticsearch("https://localhost:9200", ca_certs="./http_ca.crt", basic_auth=("elastic", "PASSWORD"))
>>> es.index(index='my_index', id=1, document={'text': 'this is a test'})
ObjectApiResponse({'_index': 'my_index', '_id': '1', '_version': 1, 'result': 'created', '_shards': {'total': 2, 'successful': 1, 'failed': 0}, '_seq_no': 0, '_primary_term': 1})
>>> es.search(index='my_index', query={'match': {'text': 'this test'}})
ObjectApiResponse({'took': 98, 'timed_out': False, '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 1, 'relation': 'eq'}, 'max_score': 0.5753642, 'hits': [{'_index': 'my_index', '_id': '1', '_score': 0.5753642, '_source': {'text': 'this is a test'}}]}})
Все ок
Хочу теперь прописать ELASTICSEARCH_URL в .env файле:
ELASTICSEARCH_URL = "http://localhost:9200", ca_certs="./http_ca.crt", basic_auth=("elastic", "password")
flask shell ругается:
Python-dotenv could not parse statement starting at line 4
если оставляю :
ELASTICSEARCH_URL = "http://localhost:9200"
Сначала не ругается , но потом , при вводе данных - ошибка:
Traceback (most recent call last):
File "<console>", line 2, in <module>
File "/var/www/project_flask/app/search.py", line 9, in add_to_index
current_app.elasticsearch.index(index=index, id=model.id, document=payload)
File "/var/www/project_flask/venv/lib/python3.10/site-packages/elasticsearch/_sync/client/utils.py", line 446, in wrapped
return api(*args, **kwargs)
File "/var/www/project_flask/venv/lib/python3.10/site-packages/elasticsearch/_sync/client/__init__.py", line 2424, in index
return self.perform_request( # type: ignore[return-value]
File "/var/www/project_flask/venv/lib/python3.10/site-packages/elasticsearch/_sync/client/_base.py", line 271, in perform_request
response = self._perform_request(
File "/var/www/project_flask/venv/lib/python3.10/site-packages/elasticsearch/_sync/client/_base.py", line 316, in _perform_request
meta, resp_body = self.transport.perform_request(
File "/var/www/project_flask/venv/lib/python3.10/site-packages/elastic_transport/_transport.py", line 342, in perform_request
resp = node.perform_request(
File "/var/www/project_flask/venv/lib/python3.10/site-packages/elastic_transport/_node/_http_urllib3.py", line 202, in perform_request
raise err from None
: Connection error caused by: ConnectionError(Connection error caused by: ProtocolError(('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))))
Как впихнуть cert, юзера и пароль в ELASTICSEARCH_URL?