Search code examples
djangosolrdjango-haystackwhoosh

Django haystack doesn't add to Solr index. [Works with whoosh, fails with Solr]


During development I used whoosh as a backend, and now want to switch to solr. I installed solr, changed the settings, to HAYSTACK_SEARCH_ENGINE, and HAYSTACK_SOLR_URL.

Now when I try to update or rebuild the index it fails with Failed to add documents to Solr: [Reason: None] .

All searches are also wrong with 0 results returned for all queries.. This work if I change to whoosh. However, I have a RealTimeSearch index set, and during model creation I am getting no warning about not being able to write to search index. (From which I am assuming that data is being correctly being written to solr index.

I can see that solr is running by going directly to the port where solr started.


Solution

  • This error usually happens when your schema.xml file is improperly configured.

    You can use python manage.py build_solr_schema > schema.xml to generate the schema.

    In order to actually have solr use it, you typically place it in example/solr/conf/schema.xml

    Finally: watch the log output of your Solr server. During development I have it running via java -jar start.jar and it implicitly prints to my screen. Otherwise, your logs go into the example/logs directory.


    Additionally, double check the HAYSTACK_SOLR_URL. It should not have a trailing slash.