2016-02-12 96 views
0

它是这个错误的原因? 我使用django1.9和Django的草垛== 2.4.1python - Haystack + Django 1.9 + Elasticsearch错误

(venv)[email protected]:~/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'}}]) 

回答

0

编辑: 可以使用从GitHub V2.5最新版本,其中有这些变化还是让他们自己。最终它归结为小便误差差models.py文件处理他们捕获异常没有日志记录,并继续与模型=无


好像大海捞针2.4不Django的1.9兼容。我解决了这个问题通过删除上下文功能,只有即返回字典:

in fields.py Line 137 

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

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

要做到这一点,你需要直接编辑站点包的来源 - 如果你正在使用虚拟信封,你应该,然后只是去ENV/lib中/ Python的* * /站点包/草垛

其他问题,我碰到:

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) 
+0

如果您使用Elasticseach> = 2.X,则必须小心,因为Haystack与它不兼容。 – primoz

+0

似乎在上述修复之后运行。 – pypypy

+0

@pypypyI一直在试图找出为什么我的修复后不能使用results.objects.get_absolute_url这个工作吗?我注意到你提到过在虚拟世界中。这不会在生产中起作用吗? – losee