0

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]
Heena
  • 61
  • 2
  • 10

1 Answers1

1

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)
MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • From where can i get the collection_name (or) core_name? – Mahesh Oct 18 '22 at 11:26
  • 1
    If you've created the collection or the core yourself (or your application did it for you), you gave the name when creating the collection or core - if not (for example if you've inherited a setup), you can go to Solr's admin page (by default on `/solr/` on the host) and see the available cores and collections. – MatsLindh Oct 18 '22 at 11:27
  • Thanks. I tried to add a new core but I am getting the error `Error CREATEing SolrCore 'new_core': Unable to create core [new_core] Caused by: Can't find resource 'solrconfig.xml' in classpath or '/var/solr/data/new_core'` on my UBUNTU machine – Mahesh Oct 18 '22 at 11:36
  • 1
    You need to have all the configuration files in place already if you're manually creating a core, i.e. you'll have to create the solrconfig.xml first before creating the core. But please ask a new question instead of having a dialog in the comments of an old, unrelated question. – MatsLindh Oct 18 '22 at 11:41
  • Thanks..It was a long process but finally I was able to create a core but I guess using a k8s solr operator would be better right? – Mahesh Oct 22 '22 at 07:18
  • 1
    That would depend on what you already have in your infrastructure. Getting up to speed on k8s + everything that goes with that is a far greater task than setting up a standalone Solr server that runs by itself and does what you want it to do. If you're already using k8s and have experience with what it takes (and the pitfalls of) running a service on that, the solr operator is a good way to do so. – MatsLindh Oct 22 '22 at 19:50