Failed to add documents to Solr: [Reason: Error 404 Not Found]
Asked Answered
S

1

3

I'm trying to index a model in Solr with django-haystack, but it returns me the following error(when using rebuild_index or update_index) :

Failed to add documents to Solr: [Reason: Error 404 Not Found]

This is search_indexes.py

from haystack import indexes
from haystack.indexes import SearchIndex
from jobpost.models import *



class JobIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    post_type = indexes.CharField(model_attr='post_type')
    location = indexes.CharField(model_attr='location')
    job_type = indexes.CharField(model_attr='job_type')
    company_name = indexes.CharField(model_attr='company_name')
    title = indexes.CharField(model_attr='title')

    def get_model(self):
        return jobpost

    def index_queryset(self,**kwargs):
        return self.get_model().objects.all()

haystack connection:

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

        'SITECONF': 'jobpost.search_sites'
    },
}

I have generated schema.xml many times restarted solr..placed it in solr/conf..don't know what's the isuue

Sisal answered 7/5, 2013 at 5:41 Comment(5)
Is it started and you can browse to the solr server by visiting 127.0.0.1:8983/solr ?Distillery
Check the solr logs and post what the error is, pleaseDistillery
org.apache.solr.common.SolrException: ERROR: [doc=jobpost.jobpost.1] unknown field 'django_id'Sisal
Your schema.xml is wrong. It's lacking the field django_id. Could you post your schema.xml, please? You probably have generated the schema but not copied it into your Solr installation.Distillery
using another version of solr solved itSisal
T
5

As specified in settings docs you need to specify the url to your core. Seems like you've missed the core in your URL. You need to create a core and the url should look like this:

'URL': 'http://localhost:9001/solr/default',
Travertine answered 23/4, 2015 at 20:47 Comment(2)
my old code didn't need to specify the last solr/default, but after updating a few things, I need to use the full url you specified. Not sure which specific version upgrade caused it.Peregrine
I have even specified the core then also it is not workingWarwick

© 2022 - 2024 — McMap. All rights reserved.