1
每當我在django Haystack中用SearchQuerySet指定.values()時,我得到一個Keyerror。對於例如在Django乾草堆Keyerror u'_source與Elasticsearch後端
required_output = SearchQuerySet()[:10]
工作正常。但是,每當我做下面的事時,它每次都拋出KeyError。
required_output = SearchQuerySet().values('title', 'slug')[:10]
這裏是錯誤的引用:
回溯:
File "/home/project_env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/home/project_env/myproject/source/apps/Project/views.py" in get
151. context = self.get_context_data(object=self.object)
File "/home/project_env/myproject/source/apps/Project/views.py" in get_context_data
108. context['related_project'] = SearchQuerySet().values('title')[:10]
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in __getitem__
266. self._fill_cache(start, bound)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in _fill_cache
656. return super(ValuesListSearchQuerySet, self)._fill_cache(start, end, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in _fill_cache
166. results = self.query.get_results(**kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/__init__.py" in get_results
645. self.run(**kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in run
918. results = self.backend.search(final_query, **search_kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/__init__.py" in wrapper
35. return func(obj, query_string, *args, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in search
504. distance_point=kwargs.get('distance_point'), geo_sort=geo_sort)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in _process_results
580. source = raw_result['_source']