我尝试在 django 项目中迭代 elasticsearch。但是当我执行命令时python manage.py search_index --rebuild
出现了这个错误
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7fde186b2b50>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7fde186b2b50>: Failed to establish a new connection: [Errno 111] Connection refused)
运行docker-compose后,我可以通过chrome访问elasticsearch http://localhost:9200。
这是setting.py文件:
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_elasticsearch_dsl',
]
ELASTICSEARCH_DSL={
'default': {
'hosts': 'localhost:9200'
},
}
Run Code Online (Sandbox Code Playgroud)
和 document.py 文件:
from django_elasticsearch_dsl import Document
from django_elasticsearch_dsl.registries import registry
from .models import Question
@registry.register_document …Run Code Online (Sandbox Code Playgroud)