Can't build index for solr/haystack: unknown f

2019-02-14 23:37发布

问题:

I'm trying to follow along the haystack tutorial. I run into an error when I run manage.py rebuild index

I get the following error:

WARNING: This will irreparably remove EVERYTHING from your search index.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y

Removing all documents from your index because you said so.
All documents removed.
/Users/heri0n/python_env/lib/python2.7/site-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2013-04-07 16:14:15.481145) while time zone support is active.
  RuntimeWarning)
Indexing 1 notes.
Failed to add documents to Solr: [Reason: None]
<response><lst name="responseHeader"><int name="status">400</int><int name="QTime">6</int></lst><lst name="error"><str name="msg">ERROR: [doc=haystacktester.note.3] unknown field 'django_id'</str><int name="code">400</int></lst></response>

I did run manage.py build_solr_schema > ~/solr-4.2.1/example/solr/conf/schema.xml

I had to create the conf directory manually as it did not exist. I noticed the tutorial uses Solr 3 while I'm on 4. Did the location of the conf dir change perhaps?

回答1:

The problem is with the Solr (haystack document use v3.5.0, here you may be using the latest) not finding the configuration file. These 3 steps worked for me

  • Place the schema in solr-x.y.z/example/solr/collection1/conf/schema.xml

  • In the schema change stopwords_en.txt to lang/stopwords_en.txt

  • Add the version field (as mentioned below) to the schema in the fields section

    <field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
    

For more information check out the same discussion in GitHub



回答2:

This is more of a comment, but due to my lack of points I am unable to comment...

Has anyone figure out a soltuion to this? I'm having the exact same problem. The field is being created in schema.xml as such:

<field name="django_id" type="string" indexed="true" stored="true" multiValued="false"/>

I have restarted Solr (multiple times), and I am 100% positive my schema.xml code is correct. What the heck is going on here?

EDIT: I switched to Elasticsearch and have no problems. However, I'm sure others out there would find help to this question useful.



回答3:

I had to clone the haystack source code and do some hacks as follows :

In the /haystack/management/commands/build_solr_schema.py , I commented DJANGO_ID in the build_context() func. Then in /haystack/templates/search_configuration/solr.xml , I replaced {{ DJANGO_ID }} with "django_id" and everything worked ok.

I think the {{DJANGO_ID}} is not being replaced with "django_id" when you generate schema.xml.