Django Haystack + Elasticsearch奇怪的间歇性错误

时间:2018-06-21 08:53:09

标签: django python-3.x elasticsearch django-haystack

Elasticsearch的{​​{3}}面临一个奇怪的问题。

一切正常(索引,查询...),但是有时(并且我无法确定根本原因),查询索引崩溃并出现以下错误:

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
 35.             response = get_response(request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
 128.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
 126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
 21.                 return view_func(request, *args, **kwargs)

File "/home/django/prod/mysite/forum/api.py" in get_topics
 66.     topics_list = SearchQuerySet().filter(**filter).models(Topic)

File "/usr/local/lib/python3.5/dist-packages/haystack/query.py" in __init__
 29.         self._determine_backend()

File "/usr/local/lib/python3.5/dist-packages/haystack/query.py" in _determine_backend
 55.         backend_alias = connection_router.for_read(**hints)

File "/usr/local/lib/python3.5/dist-packages/haystack/utils/loading.py" in for_read
 167.         return self._for_action('for_read', False, **hints)[0]

Exception Type: IndexError at /forum/api/get-topics/
Exception Value: list index out of range

问题似乎出在_determine_backend函数上。

我的后端在Django设置文件中以这种方式配置:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.elasticsearch2_backend.Elasticsearch2SearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'myindex',
    },
}

在我的生产服务器(Python 3.5)和我的开发人员(Python 3.6)上都是相同的。

干草堆版本为:

django-haystack==2.8.1
  - Django [required: >=1.11, installed: 2.0.6]
    - pytz [required: Any, installed: 2018.4]
elasticsearch==2.4.1
  - urllib3 [required: <2.0,>=1.8, installed: 1.23]

您经历过这样的事情吗?

提前谢谢!

0 个答案:

没有答案