1

我正在使用简单的 Python 脚本使用 Pysolr 从 Solr 获取示例数据。首先,我使用以下内容创建了我的核心

[user@user solr-7.1.0]$ ./bin/solr create -c json_db
WARNING: Using _default configset. Data driven schema functionality is enabled by default, which is
         NOT RECOMMENDED for production use.

         To turn it off:
            curl http://localhost:8983/solr/json_db/config -d '{"set-user-property": {"update.autoCreateFields":"false"}}'

Created new core 'json_db'


[user@user solr-7.1.0]$ ./bin/post -c json_db example/exampledocs/*.json
SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/json_db/update...
Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
POSTing file books.json (application/json) to [base]/json/docs
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/json_db/update...
Time spent: 0:00:00.398

创建核心后,我运行简单的 python 脚本来获取数据

from pysolr import Solr

conn = Solr('http://localhost:8983/solr/json_db/')
results = conn.search('*:*')

我收到此错误

Traceback (most recent call last):
  File "/home/user/PycharmProjects/APP/application/solr_test.py", line 4, in <module>
    results = conn.search({'*:*'})
  File "/home/user/PycharmProjects/APP/venv/lib/python3.5/site-packages/pysolr.py", line 723, in search
    response = self._select(params, handler=search_handler)
  File "/home/user/PycharmProjects/APP/venv/lib/python3.5/site-packages/pysolr.py", line 421, in _select
    return self._send_request('get', path)
  File "/home/user/PycharmProjects/APP/venv/lib/python3.5/site-packages/pysolr.py", line 396, 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]

但是当我尝试直接从 solr 运行查询时,我得到如下结果在此处输入图像描述

有人可以指导我在这里做错了什么吗?谢谢

4

1 回答 1

0

您可以在不使用pysolr库的情况下运行下面的脚本来获取结果。

#! /usr/bin/python
import urllib
import json as simplejson
import pprint
import sys

url = 'give the url here'
wt = "wt=json"
connection = urllib.urlopen(url)

if wt == "wt=json":
  response   = simplejson.load(connection) 
else:
  response   = eval(connection.read())

print "Number of hits: " + str(response['response']['numFound'])
pprint.pprint(response['response']['docs'])
于 2020-09-28T12:42:01.630 回答