使用Python的Apache Solr

时间:2019-01-17 07:25:54

标签: python solr pysolr

我是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]

1 个答案:

答案 0 :(得分:0)

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

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