gpt4 book ai didi

django - django-haystack 和 elasticsearch 中缺少 connection_alias 参数

转载 作者:行者123 更新时间:2023-12-02 22:27:52 26 4
gpt4 key购买 nike

带有 elasticsearch 的 Django-haystack 缺少“connection_alias”参数。

我正在设置一个 django 应用程序,其中 django-haystack 使用 elasticsearch 作为搜索引擎后端。但是,模块中缺少“connection_alias”参数

HAYSTACK_CONNECTIONS 在 settings.py 中设置了 elasticsearch

HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchBackend',
'URL': 'http://127.0.0.1:9200',
'INDEX_NAME': 'haystack',
}
}

search_indexes.py 模型也在下面设置:

from haystack import indexes
from .models import Post


class PostIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
publish = indexes.DateTimeField(model_attr='publish')

def get_model(self):
return Post

def index_queryset(self):
return self.get_model().published.all()

但是,在 django 应用程序的 manage.py 中运行 rebuild_index 命令时:
./manage.py rebuild_index

出现错误,表明“connection_alias”缺少参数
Traceback (most recent call last):
File "./manage.py", line 21, in <module>
main()
File "./manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/haystack/management/commands/rebuild_index.py", line 41, in handle
call_command('clear_index', **clear_options)
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 148, in call_command
return command.execute(*args, **defaults)
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/haystack/management/commands/clear_index.py", line 52, in handle
backend = connections[backend_name].get_backend()
File "/home/giddyupyup/Documents/Development/Python/projects/blogapp/venv/lib/python3.6/site-packages/haystack/utils/loading.py", line 109, in __getitem__
self.thread_local.connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key)
TypeError: __init__() missing 1 required positional argument: 'connection_alias'


干草堆环境是否需要任何额外的设置才能正常工作?

我正在使用这个 Django 设置环境:
Django==2.2
django-haystack==2.8.1
elasticsearch==5.5.3

请帮忙。

最佳答案

您可能已经解决了这个问题,但对于遇到这里的每个人来说,它发生的简单原因是因为您需要指定 发动机 而不是后端。

...
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
...

https://django-haystack.readthedocs.io/en/master/settings.html#haystack-connections

关于django - django-haystack 和 elasticsearch 中缺少 connection_alias 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55755749/

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