尝试使用ElasticSearch后端更新update_index时出错

时间:2018-01-30 19:56:36

标签: python django elasticsearch wagtail

我有一个Django环境设置为使用ElasticSearch作为我们CMS的后端,这是Wagtail。我安装了最新版本的ES(根据我的CURL时的服务为5.6.5),并使用'wagtail.wagtailsearch.backends.elasticsearch5'作为WAGTAILSEARCH_BACKENDS的'BACKEND'设置我的设置文件。根据我的pip冻结,Wagtail在1.13.1版本上,而弹性搜索Python包是在5.5.2。根据{{​​3}}的阅读,这一切似乎都是正确的。

我遇到的问题是,当我尝试执行'./manage.py update_index'时,它会给我以下错误:

$ ./manage.py update_index 
Updating backend: default
default: Rebuilding index wagtail__wagtailcore_page
Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/management/commands/update_index.py", line 120, in handle
    self.update_backend(backend_name, schema_only=options.get('schema_only', False))
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/management/commands/update_index.py", line 77, in update_backend
    index.add_model(model)
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/backends/elasticsearch2.py", line 113, in add_model
    index=self.name, doc_type=mapping.get_document_type(), body=mapping.get_mapping(),
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 137, in get_mapping
    self.get_field_mapping(field) for field in self.model.get_search_fields()
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 137, in <genexpr>
    self.get_field_mapping(field) for field in self.model.get_search_fields()
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/backends/elasticsearch.py", line 119, in get_field_mapping
    return self.get_field_column_name(field), mapping
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/backends/elasticsearch2.py", line 56, in get_field_column_name
    return prefix + field.get_attname(self.model)
  File "/home/vagrant/.virtualenvs/wrds/lib/python3.5/site-packages/wagtail/wagtailsearch/index.py", line 178, in get_attname
    return field.attname
AttributeError: 'ManyToOneRel' object has no attribute 'attname'

正如我所提到的,ES服务正在运行并给出了对CURL的预期回复。我在这里不知道如何解决这个错误。谷歌搜索错误并没有多大帮助:http://docs.wagtail.io/en/v1.13.1/topics/search/backends.html似乎表明问题可能是'延迟/仅用于模型中具有明确删除的反向关系的字段',但我已经搜索了我们的代码,我很确定我们根本没有使用only()defer(),更不用说删除了反向关系的表/字段。任何帮助当然非常感谢!

1 个答案:

答案 0 :(得分:1)

我发现了麻烦。这个问题不在我们项目的代码中,而是在wagtailgridder(v.9.2.18)中的GridIndexPage类的search_fields中。我知道wagtailgridder的开发者,他将在那里做出必要的改变。谢谢你的帮助,@ gasman!你的建议把我带到了正确的地方。