我正在尝试使用django-haystack索引Solr中的模型,但它返回以下错误(使用rebuild_index或update_index时):
Indexing 2 jobposts
Failed to add documents to Solr: [Reason: None]
<response><lst name="responseHeader"><int name="status">400</int><int name="QTime">358</int></lst><lst name="error"><str name="msg">ERROR: [doc=jobpost.jobpost.1] unknown field 'django_id'</str><int name="code">400</int></lst></response>
这是search_indexes.py
from haystack import indexes
from haystack.indexes import SearchIndex
from jobpost.models import *
class JobIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
post_type = indexes.CharField(model_attr='post_type')
location = indexes.CharField(model_attr='location')
job_type = indexes.CharField(model_attr='job_type')
company_name = indexes.CharField(model_attr='company_name')
title = indexes.CharField(model_attr='title')
def get_model(self):
return jobpost
def index_queryset(self,**kwargs):
return self.get_model().objects.all()
答案 0 :(得分:2)
您需要更新solr引擎的schema.xml
,因为它写成here:
“你需要修改你的架构。你可以通过运行./manage.py build_solr_schema从你的应用程序生成这个(一旦安装和设置Haystack)。从该命令获取输出并将其放在apache-solr中-3.5.0 / example / solr / conf / schema.xml。然后重新启动Solr。“