gpt4 book ai didi

django - 干草堆 : KeyError in the elasticsearch_backend module

转载 作者:行者123 更新时间:2023-12-03 01:08:40 25 4
gpt4 key购买 nike

我正在使用 Django + Haystack + Elasticsearch。

当我向这个 View 发送请求时

from haystack.views import FacetedSearchView

from .models import Object


class ObjectView(FacetedSearchView):

def extra_context(self):
extra = super(ObjectView, self).extra_context()

if not self.results:
extra['objects'] = Object.objects.all()
else:
searchqueryset = self.form.search()
results = [ result.pk for result in searchqueryset ]
extra['facets'] = self.results.facet_counts()
extra['objects'] = Object.objects.filter(pk__in=results)
extra['results'] = self.results
return extra

引发此错误:
  File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/views.py", line 49, in __call__
return self.create_response()

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/views.py", line 129, in create_response
(paginator, page) = self.build_page()

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/views.py", line 106, in build_page
self.results[start_offset:start_offset + self.results_per_page]

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/query.py", line 266, in __getitem__
self._fill_cache(start, bound)

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/query.py", line 164, in _fill_cache
results = self.query.get_results(**kwargs)

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 485, in get_results
self.run(**kwargs)

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 942, in run
results = self.backend.search(final_query, **search_kwargs)

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/backends/__init__.py", line 26, in wrapper
return func(obj, query_string, *args, **kwargs)

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 521, in search
distance_point=kwargs.get('distance_point'), geo_sort=geo_sort)

File "/home/deploy/.virtualenvs/deploy/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 571, in _process_results
raw_suggest = raw_results['suggest']['suggest']

KeyError: 'suggest'

一个奇怪的事实:只有在项目处于生产设置时才会出现问题,即使我没有更改 settings_production 模块中涉及 Haystack 或 Elasticsearch 的任何内容(URL 键除外)。

项目/settings_production.py
'URL': 'http://0.0.0.0:9200/'

在生产中,我只使用一个简单的 FastCGI。

这就是真正困扰我的地方:有时我在这个 View 上没有任何错误,而且一切都很好......

拜托,有人知道发生了什么吗?

非常感谢!

更新:

所以,我在另一台计算机上设置了我的整个项目。经过一些测试,我验证了:
  • 这个问题与我的生产设置无关
    如上所述;
  • 停止 Elasticsearch 服务时不会引发错误;
  • 如果 服务是正在运行 :
  • 当方法Object.objects.all()返回一些 QuerySet 结果,我没有错误;
  • 当方法Object.objects.all()返回一个空的QuerySet,问题依旧;

  • 我猜这是 Haystack 的 elasticsearch_backend 模块中的某种错误。

    不过,我不确定。

    最佳答案

    是的,这是大海捞针中的一个错误。我已经输入了 pull request ,但与此同时,运行的选项是:

  • 设置 INCLUDE_SPELLING在你的大海捞针设置到False , 或
  • 使用我们的 fork :https://github.com/greenkahuna/django-haystack
  • 关于django - 干草堆 : KeyError in the elasticsearch_backend module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18961894/

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