我正在試驗(yàn) Elasticsearch 并使用elasticsearch-dslPython 包索引一些 Django 數(shù)據(jù)。我創(chuàng)建了一個(gè)相對(duì)基本的測(cè)試,search.py但是當(dāng)我嘗試索引任何數(shù)據(jù)時(shí)收到連接錯(cuò)誤。from elasticsearch_dsl.connections import connectionsfrom elasticsearch_dsl import Document, Textfrom elasticsearch.helpers import bulkfrom elasticsearch import Elasticsearchfrom . import modelsconnections.create_connection(hosts=['ELASTICSEARCH_ENDPOINT_URL'], http_auth='USERNAME:PASSWORD')class MyIndex(Document): title = Text() description = Text() class Index: name = 'my-index'def bulk_indexing(): MyIndex.init() es = Elasticsearch() bulk(client=es, actions=(a.indexing() for a in models.MyModel.objects.all().iterator()))當(dāng)我運(yùn)行時(shí),bulk_indexing()我收到以下錯(cuò)誤:elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x1282266d8>: Failed to establish a new connection: [Errno 61] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x1282266d8>: Failed to establish a new connection: [Errno 61] Connection refused)我懷疑語法錯(cuò)誤或在創(chuàng)建連接時(shí)丟失了一些憑據(jù),但我找不到任何進(jìn)一步的信息。我正在使用使用 Elastic Cloud 部署的 Elasticsearch v7.4.0。當(dāng)我通過瀏覽器訪問 URL 時(shí),我可以連接。
1 回答

慕田峪9158850
TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
為什么不簡(jiǎn)單地使用您的 Cloud ID(您可以在 ES Cloud 控制臺(tái)中找到)?
from elasticsearch import Elasticsearch
es = Elasticsearch(cloud_id="<some_long_cloud_id>", http_auth=('USERNAME','PASSWORD'))
添加回答
舉報(bào)
0/150
提交
取消