Apache Solr 使用 Python

Apache Solr using Python

我是 Apache Solr 的新手。当我在 python 中使用 pysolr 包添加文档时出现错误。

我试过以下方法:

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",
    }
])

我收到以下错误:

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]

name of your core or collection should be part of the URL,以及/solr路径前缀:

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