SolrError:Solr回应了一个错误(HTTP 400):[原因:错误:[doc=auth.user.23]未知字段“名字”]

wz8daaqr  于 2022-11-05  发布在  Solr
关注(0)|答案(1)|浏览(170)

我尝试使用Django-Haystack-Solr在'User'模型的'first_name'字段上实现自动完成。但是我遇到了这个“未知字段”的错误。

搜索索引.py:

from haystack import indexes
from django.contrib.auth.models import User

class UserIndex(indexes.SearchIndex, indexes.Indexable):
      text = indexes.CharField(document=True, use_template=True)
      firstname = indexes.EdgeNgramField(model_attr='first_name')

      def get_model(self):
          return User

      def index_queryset(self, using=None):
          return self.get_model().objects.all()

查看次数.py

results = SearchQuerySet().autocomplete(firstname=request.POST.get("search_text",''))

我执行了以下操作:
1.跑过来指挥:$ python manage.py构建解决方案
1.已将新模式保存到schema.xml
1.跑过来指挥:$ python manage.py rebuild_index ---〉抛出错误

错误:

Indexing 5 users 
 /usr/local/lib/python2.7/dist-packages/haystack/fields.py:137: RemovedInDjango110Warning: render() must be called with a dict, not a Context.
 return t.render(Context({'object': obj}))

 Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [doc=auth.user.23] unknown field 'firstname']
 Traceback (most recent call last):
 File "/usr/local/lib/python2.7/dist-packages/haystack/backends/solr_backend.py", line 72, in update
     self.conn.add(docs, commit=commit, boost=index.get_field_weights())
 File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 860, in add
     return self._update(m, commit=commit, softCommit=softCommit, waitFlush=waitFlush, waitSearcher=waitSearcher)
 File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 462, in _update
     return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
 File "/usr/local/lib/python2.7/dist-packages/pysolr.py", line 394, in _send_request
     raise SolrError(error_message % (resp.status_code, solr_message))
 SolrError: Solr responded with an error (HTTP 400): [Reason: ERROR: [doc=auth.user.23] unknown field 'firstname']

另外,如果有人能告诉我如何为多个字段实现自动完成功能,我该怎么做呢?

解答-重新启动Solr

Stop Solr:   ./solr-4.10.4/bin/solr stop -all
Start Solr:  ./solr-4.10.4/bin/solr start -p 8983
3gtaxfhh

3gtaxfhh1#

如果您正在尝试向Solr 9添加文档,请使用下面的行添加它们...

import pysolr
solr = pysolr.Solr('http://localhost:8983/solr/core/', always_commit=True)
docs = {"id":3,"title": "Solr"} #This is what Solr LIKES. Solr will through an error if your do nested dictionary like this {"id":3,"title": "Solr", "_links": {"self": {"href": "/api/entries/7"}}}
solr.add(doc,commit=True)

当我嵌套字典时,在我的例子中得到的错误是SolrError: Solr responded with an error (HTTP 400): [Reason: Error:[doc=3] Unknown operation for the an atomic update: self]

相关问题