python - 如何解决django HayStack、elasticsearch update_index错误?

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


我使用 django Web 框架集成了 elasticsearch 和 haystack。现在我想删除不存在的 使用 call_command('update_index --remove') 函数从 Elasticsearch 索引中获取数据。

我的问题是当我运行update_index --remove时我产生以下错误:

Indexing 6 notes
[ERROR/MainProcess] Error updating core using default 
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", 
line 230, in handle
self.update_backend(label, using)
File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", 
line 308, in update_backend
index_total = SearchQuerySet(using=backend.connection_alias).models(model).count()
File "/usr/local/lib/python3.6/dist-packages/haystack/query.py", line 522, in count
return len(self)
File "/usr/local/lib/python3.6/dist-packages/haystack/query.py", line 86, in __len__
self._result_count = self.query.get_count()
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/__init__.py", line 619, in 
get_count
self.run()
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/elasticsearch_backend.py", 
line 951, in run
results = self.backend.search(final_query, **search_kwargs)
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/__init__.py", line 33, in 
wrapper
return func(obj, query_string, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/elasticsearch_backend.py", 
line 524, in search
_source=True)
File "/usr/local/lib/python3.6/dist-packages/elasticsearch/client/utils.py", line 84, in 
_wrapped
return func(*args, params=params, **kwargs)
TypeError: search() got an unexpected keyword argument 'doc_type'
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, 
in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, 
in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 316, in 
run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 353, in 
execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", 
line 230, in handle
self.update_backend(label, using)
File "/usr/local/lib/python3.6/dist-packages/haystack/management/commands/update_index.py", 
line 308, in update_backend
index_total = SearchQuerySet(using=backend.connection_alias).models(model).count()
File "/usr/local/lib/python3.6/dist-packages/haystack/query.py", line 522, in count
return len(self)
File "/usr/local/lib/python3.6/dist-packages/haystack/query.py", line 86, in __len__
self._result_count = self.query.get_count()
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/__init__.py", line 619, in 
get_count
self.run()
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/elasticsearch_backend.py", 
line 951, in run
results = self.backend.search(final_query, **search_kwargs)
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/__init__.py", line 33, in 
wrapper
return func(obj, query_string, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/haystack/backends/elasticsearch_backend.py", 
line 524, in search
_source=True)
File "/usr/local/lib/python3.6/dist-packages/elasticsearch/client/utils.py", line 84, in 
_wrapped
return func(*args, params=params, **kwargs)
TypeError: search() got an unexpected keyword argument 'doc_type'

我正在使用:
django-haystack==2.8.1
elasticsearch==7.1.0
elasticsearch-7.4.0 => 服务器

注意:
不推荐

HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

这个方法不适合我。我没有使用 django 进行数据插入。仅用于过滤和删除目的。

update_index --age=24 也存在同样的问题。

最佳答案

我相信问题是您使用的是 Elasticsearch 7,并且 Haystack only supports versions up to 5 :

Haystack currently only supports Elasticsearch 1.x and 2.x. Elasticsearch 5.x is not supported yet, if you would like to help, please see #1383.

我看到两个选项:

  • 保留 Haystack 并使用 Elasticsearch 5 服务器,
  • 放弃 Haystack 并使用“ Vanilla ”Elasticsearch python client并手动执行查询(也可以执行普通 HTTP 请求)。

您看到的错误:

TypeError: search() got an unexpected keyword argument 'doc_type'

与 Elasticsearch 7 中删除了文档类型这一事实有关。

关于python - 如何解决django HayStack、elasticsearch update_index错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59410030/

相关文章:

python - 错误没有名为 curses 的模块

python - NumPy:了解颜色矩阵中的值

python - colorbar matplotlib python 上的 onclick 方法

python - django,fastcgi : how to manage a long running process?

python - 为什么有时候 Django 的开发服务器会挂掉?

python - 解析右结合运算符(指数)

python - 执行 Selenium 时意外的窗口位置移动

python - 求和产品和分组

python - 如何访问 PySide2 中选中的 QCheckBox?

python - 要求用户提供输入,直到他们给出有效的答复