python - Haystack + Django 1.9 + Elasticsearch错误

时间:2016-02-12 02:35:36

标签: elasticsearch django-haystack django-1.9

这是导致此错误的原因? 我正在使用django1.9和django-haystack == 2.4.1

(venv)daniel@daniel22:~/prototipos/venv/ejemplo/exp$ python manage.py update_index

Indexing 2 documents
/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/fields.py:137: RemovedInDjango110Warning: render() must be called with a dict, not a Context.
  return t.render(Context({'object': obj}))

ERROR:root:Error updating art using default 
Traceback (most recent call last):
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 188, in handle_label
    self.update_backend(label, using)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 233, in update_backend
    do_update(backend, index, qs, start, end, total, verbosity=self.verbosity, commit=self.commit)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 96, in do_update
    backend.update(index, current_qs, commit=commit)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 193, in update
    bulk(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 188, in bulk
    for ok, item in streaming_bulk(client, actions, **kwargs):
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 160, in streaming_bulk
    for result in _process_bulk_chunk(client, bulk_actions, raise_on_exception, raise_on_error, **kwargs):
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 132, in _process_bulk_chunk
    raise BulkIndexError('%i document(s) failed to index.' % len(errors), errors)
BulkIndexError: (u'2 document(s) failed to index.', [{u'index': {u'_type': u'modelresult', u'_id': u'art.document.1', u'ok': True, u'_version': 4, u'_index': u'haystack'}}, {u'index': {u'_type': u'modelresult', u'_id': u'art.document.2', u'ok': True, u'_version': 4, u'_index': u'haystack'}}])
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 183, in handle
    return super(Command, self).handle(*items, **options)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 548, in handle
    label_output = self.handle_label(label, **options)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 188, in handle_label
    self.update_backend(label, using)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 233, in update_backend
    do_update(backend, index, qs, start, end, total, verbosity=self.verbosity, commit=self.commit)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 96, in do_update
    backend.update(index, current_qs, commit=commit)
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 193, in update
    bulk(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 188, in bulk
    for ok, item in streaming_bulk(client, actions, **kwargs):
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 160, in streaming_bulk
    for result in _process_bulk_chunk(client, bulk_actions, raise_on_exception, raise_on_error, **kwargs):
  File "/home/daniel/prototipos/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 132, in _process_bulk_chunk
    raise BulkIndexError('%i document(s) failed to index.' % len(errors), errors)
elasticsearch.helpers.BulkIndexError: (u'2 document(s) failed to index.', [{u'index': {u'_type': u'modelresult', u'_id': u'art.document.1', u'ok': True, u'_version': 4, u'_index': u'haystack'}}, {u'index': {u'_type': u'modelresult', u'_id': u'art.document.2', u'ok': True, u'_version': 4, u'_index': u'haystack'}}])

1 个答案:

答案 0 :(得分:0)

编辑: 您可以使用github v2.5中的最新版本进行这些更改或自行制作。归根结底,它归结为在models.py文件中糟糕的错误处理,它们在没有记录的情况下捕获异常并继续使用model = None

似乎haystack 2.4不兼容Django 1.9。我通过删除上下文函数并仅返回dict来修复此问题,即:

in fields.py Line 137

Before:
return t.render(Context({'object': obj}))

After:
return t.render({'object': obj})

要做到这一点,你需要直接编辑site-package的源代码 - 如果你使用的是Virtual Env,那么你应该这样做,然后去env / lib / python *。* / site-packages / haystack < / p>

我遇到的其他问题:

in urls.py
After:
    urlpatterns = [
        url(r'^$', SearchView(), name='haystack_search'),
    ]

-

in forms.py Line 110 and in Models.py line 103 and morelikethis.py line 35:

before:
self._model = apps.get_model(self.app_label, self.model_name)

after:
from django.apps import apps
self._model = apps.get_model(self.app_label, self.model_name)