I am trying to add a document to a collection in Pysolr. I have first installed solr from homebrew and started the solr server.
For the client, I am following the documentation listed here. The data I have is in JSON format. I had initially created python objects and converted them to json format but that didn't work. This is how I was trying to add data to Solr.
`
import pysolr
# Create a client instance. The timeout and authentication options are not required.
solr = pysolr.Solr('http://localhost:8983/solr/test', timeout=10)
#How you'd index data.
solr.add([
{
"id": "doc_1",
"title": "A test document",
},
{
"id": "doc_2",
"title": "The Banana: Tasty or Dangerous?",
},
])`
I got the error:
File "/Users/sushmitamallick/.pyenv/versions/3.8.13/lib/python3.8/site-packages/pysolr-3.1.0-py3.8.egg/pysolr.py", line 442, in _scrape_response TypeError: a bytes-like object is required, not 'str'
, so I tried doing a test run using a python dict instead after referring this answer:
`
import pysolr
# Create a client instance. The timeout and authentication options are not required.
solr = pysolr.Solr('http://localhost:8983/solr/test', timeout=10)
d = dict()
d["id"] = 1
d["name"] = 'sushmita'
#How you'd index data.
solr.add(a)`
This is failing with
File "/Users/sushmitamallick/.pyenv/versions/3.8.13/lib/python3.8/site-packages/pysolr-3.1.0-py3.8.egg/pysolr.py", line 680, in _build_doc AttributeError: 'str' object has no attribute 'items'
I have also tried passing in a Json array instead of a single entity, still have the same error.
Any leads would be appreciated.
I am expecting to ingest data into Solr with this command which I then plan to query with
results = solr.search('sushmita')