我正在使用elasticsearch-dsl
Python包尝试Elasticsearch和索引一些Django数据。
我已经创建了一个相对基本的测试search.py
,但是当我尝试索引任何数据时收到一个连接错误。
from elasticsearch_dsl.connections import connections
from elasticsearch_dsl import Document, Text
from elasticsearch.helpers import bulk
from elasticsearch import Elasticsearch
from . import models
connections.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()))
当我运行bulk_indexing()
时,我得到以下错误: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)
我怀疑语法错误或在创建连接时丢失了一些凭据,但我找不到任何进一步的信息。
我使用的是使用弹性云部署的Elasticsearch v7.4.0。当我通过浏览器访问URL时,我可以连接。
1条答案
按热度按时间92dk7w1h1#
为什么不简单地使用您的云ID(您可以在ES Cloud控制台中找到)?