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.

gatlanticus
  • 1,158
  • 2
  • 14
  • 28

2 Answers2

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

gatlanticus
  • 1,158
  • 2
  • 14
  • 28
1

Had the same problem and found the answer: https://stackoverflow.com/a/29833997/366722 You need to specify the core in your URL

Community
  • 1
  • 1
siavach
  • 813
  • 9
  • 10
  • Which version of solr were you using? Apparently the [the structure of the solr.xml file has changed](https://wiki.apache.org/solr/Solr.xml%204.4%20and%20beyond): "In a nutshell, [as of solr v5.0] and 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 ). – gatlanticus Apr 23 '15 at 23:44
  • That's correct. I am using 5.1.0 and setting it up using an old documentation of haystack that uses 4.x. – siavach Apr 24 '15 at 15:17