2013-05-06 37 views
1

我想指數模型Solr中與Django的草垛,但它返回我下面的錯誤(使用rebuild_index或update_index時):無法將文檔添加到Solr:原因:無]

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

看看我的答案爲同一種[問題](http://stackoverflow.com/questions/15868052/cant-build-index-for-solr-haystack-unknown-field-django -id/20661704#20661704)。它可能有幫助 – NEB 2013-12-18 15:16:11

回答

2

你需要更新你的Solr引擎schema.xml,因爲它寫here

「你需要修改你的模式你可以摹通過運行./manage.py build_solr_schema從應用程序中安裝此應用程序(一旦Haystack安裝並設置)。從該命令獲取輸出並將其放置在apache-solr-3.5.0/example/solr/conf/schema.xml中。然後重新啓動Solr。「

+0

做了很多次,但仍然出現錯誤 – 2013-05-06 09:54:54

+0

提供的錯誤告訴我們,solr找不到字段'django_id'的定義,這個字段是由'build_solr_schema'命令產生的。請檢查,如果它真的出現在'apache-solr-3.5.0/example/solr/conf/schema.xml'中,並且不要忘記重新啓動Solr – stalk 2013-05-06 09:59:46

+0

現在它說'無法將文檔添加到Solr: [原因:錯誤404未找到] ' – 2013-05-06 10:05:45