gpt4 book ai didi

python - NewConnectionError(:无法建立新连接:[Errno 111]连接被拒绝)

转载 作者:行者123 更新时间:2023-12-03 01:10:19 27 4
gpt4 key购买 nike

我正在尝试构建一个可以搜索汽车的简单django flex 搜索。但是,当我尝试重新建立索引时,它给了我上面的错误。我正在关注此文档-> quickstart elasticsearch ...下面给出了完整的追溯->

elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f09b9f0a7c0>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f09b9f0a7c0>: Failed to establish a new connection: [Errno 111] Connection refused)
我的models.py是简单的Car模型,具有名称,颜色,描述,类型filds,并在其中添加了文档
class Car(models.Model):
name = models.CharField(max_length=50)
color = models.CharField(max_length=50)
description = models.TextField()
type = models.IntegerField(choices=[
(1, "Sedan"),
(2, "Truck"),
(4, "SUV"),
])
我的documents.py文件->
from django_elasticsearch_dsl import Document
from django_elasticsearch_dsl.registries import registry
from .models import Car


@registry.register_document
class CarDocument(Document):
class Index:
name = 'cars'
settings = {'number_of_shards': 1,
'number_of_replicas': 0}

class Django:
model = Car

fields = [
'name',
'color',
'description',
'type',
]
但是当我尝试重新建立索引时,它给出了新的连接错误。我用来重建索引的命令如下->
python manage.py search_index --rebuild

最佳答案

首先,请确保您已正确安装和配置ElasticSearch服务(可以使用此document)。此错误表示您的代码无法使用当前配置连接到ElasticSearch服务。检查 flex 服务是否已启动并正在运行。在基于Linux的操作系统中,您可以通过$ sudo systemctl status elasticsearch.service进行检查,然后在结果页面中应该看到Active: active (running)行。完成此步骤后,检查url http://localhost:9200/(如果未更改默认设置),并且一切正常,那么您应该看到以下结果:

{
"name" : "some_name-System-Product-Name",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "erP_jdhLRvuwqLkx1_tehw",
"version" : {
"number" : "7.9.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "a479a2a7fce0389512d6a9361301708b92dff667",
"build_date" : "2020-08-11T21:36:48.204330Z",
"build_snapshot" : false,
"lucene_version" : "8.6.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
您也可以使用 $ sudo systemctl start elasticsearch.service启动此服务。另一种可能性是,也许您以错误的方式配置了 flex 变量。例如,使用错误的端口代替默认端口(即9200)也会引发相同的错误。在以下示例中,您可以看到将在项目的 settings.py中使用的Elastic配置示例:
# ElasticSearch configs
ELK_BASE_URL = 'elasticsearch://{username}:{password}@{host_ip}:{host_port}'
ELASTIC_SEARCH_URL = ELK_BASE_URL.format(
username='ELASTICSEARCH_USER',
password='ELASTICSEARCH_PASS',
host_ip='ELASTICSEARCH_HOST',
host_port='ELASTICSEARCH_PORT'
)
ELASTICSEARCH_DSL = {
'default': {
'hosts': [ELASTIC_SEARCH_URL]
},
}

关于python - NewConnectionError(<URLlib3.connection.HTTPConnection对象位于0x7f09b9f0a7c0>:无法建立新连接:[Errno 111]连接被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64412000/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com