django-haystack: Failed to add documents to Solr: [Reason: Error 404 Not Found]
Asked Answered
A

2

9

I'm using django-haystack (v 2.3.1) with solr (v 5.0.0) and pysolr (v 3.0.0). I've been following the tutorial, and have set up similar myapp/search_indexes.py and search/indexes/myapp/mymodel_text.txt files.

./manage.py build_solr_schema > schema.xml works fine, and I have copied this to $SOLR_HOME/conf/schema.xml.

The problem occurs when I try ./manage.py rebuild_index. First, I'm asked to confirm:

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
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

Then, it fails:

Removing all documents from your index because you said so.
Failed to clear Solr index: [Reason: Error 404 Not Found]
All documents removed.
Indexing 6 stories
Failed to add documents to Solr: [Reason: Error 404 Not Found]

My connection settings are:

#settings.py
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://127.0.0.1:8983/solr',
    },
}

If I navigate to this url I can see the solr admin page. I have made sure that port 8983 is open for solr (as well as 8000 for the Django development server).

I feel that I may not have provided enough connection information, but what else is there to check?

UPDATE:
Although I solved this problem there were more to come, which were all fixed by using solr (v.4.7.0) instead, as django-haystack isn't ready for solr 5 (there was an issue related to this but I can no longer find it on github.

Ark answered 31/3, 2015 at 6:2 Comment(0)
A
10

Thanks to user366722 for suggesting to specify the core in the settings. However, I had neglected an even more fundamental step of creating the core!

Solution:
Create the core, specifying the name of the core (e.g. 'default') and the port (e.g. 8983):

$bin/solr create_core -c default -p 8983

Then, just specify the name of the core (e.g. 'default') in your haystack URL settings:

#settings.py
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://127.0.0.1:8983/solr/default',
    },
}

Done!

Now, I get

Removing all documents from your index because you said so.
All documents removed.
Indexing 3 stories

UPDATE:
At the time of writing, I also switched to solr 4.7.0 to make it work, as haystack wasn't ready for solr 5.x

Ark answered 4/6, 2015 at 2:1 Comment(2)
bin/solr create_core -c default -p 8983 can u tell me which bin ?! ThanksColbert
which bin depends on where you installed itArk
D
1

Had the same problem and found the answer: https://mcmap.net/q/1315796/-failed-to-add-documents-to-solr-reason-error-404-not-found You need to specify the core in your URL

Deca answered 23/4, 2015 at 20:49 Comment(2)
Which version of solr were you using? Apparently the the structure of the solr.xml file has changed: "In a nutshell, [as of solr v5.0] <cores> and <core> have been replaced by auto-discovering cores." As I gave up at the time, I'm not sure if django-haystack was able to produce a compatible solr.xml file for v5 of solr (i.e. without <cores>).Ark
That's correct. I am using 5.1.0 and setting it up using an old documentation of haystack that uses 4.x.Deca

© 2022 - 2024 — McMap. All rights reserved.