pythonsolrpysolr

Apache Solr using Python


I'm new to Apache Solr. I get an error when I add the documents using pysolr package in python.

I have tried following:

from __future__ import print_function
import pysolr
solr = pysolr.Solr('http://localhost:8983', timeout=10)

solr.add([  
    {
        "id": "doc_1",
        "title": "A very small test document about elmo",
    }
])

I get the following error:

Traceback (most recent call last):
  File "ex1.py", line 16, in <module>
    { "id": "child_doc_2", "title": "seed"},
  File "/home/system/anaconda3/lib/python3.6/site-packages/pysolr.py", line 918, in add
    overwrite=overwrite, handler=handler)
  File "/home/system/anaconda3/lib/python3.6/site-packages/pysolr.py", line 500, in _update
    return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
  File "/home/system/anaconda3/lib/python3.6/site-packages/pysolr.py", line 412, in _send_request
    raise SolrError(error_message % (resp.status_code, solr_message))
pysolr.SolrError: Solr responded with an error (HTTP 404): [Reason: Error 404 Not Found]

Solution

  • The name of your core or collection should be part of the URL, as well as the /solr path prefix:

    solr = pysolr.Solr('http://localhost:8983/solr/<collectionname>', timeout=10)