刚开始学习solr。我正在尝试使用 solrpy 作为客户端。我的python代码是:
import solr
# create a connection to a solr server
s = solr.SolrConnection('http://localhost:8983/solr')
# add a document to the index
doc = dict(
id='testid123',
title='Lucene in Action',
author=['Erik Hatcher', 'Otis Gospodneti'],
)
s.add(doc, commit=True)
# do a search
response = s.query('title:lucene')
for hit in response.results:
print hit['title']
这是来自此处给出的示例
我的 solr schema.xml 是 solr 发行版附带的默认模式。我没有对此进行任何更改。它有一个 uniqueKey 字段作为“id”。
<uniqueKey>id</uniqueKey>
它是字符串类型的
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
仍然当我运行我的代码时,在我的客户端我得到错误:
Traceback (most recent call last):
File "/Users/user1/Documents/workspace/PyDelight/src/Test.py", line 12, in <module>
s.add(doc, commit=True)
File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 678, in add
return Solr.add_many(self, [fields], commit=_commit)
File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 326, in wrapper
return self._update(content, query)
File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 550, in _update
rsp = self._post(selector, request, self.xmlheaders)
File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 639, in _post
return check_response_status(self.conn.getresponse())
File "/Library/Python/2.7/site-packages/solrpy-0.9.5-py2.7.egg/solr/core.py", line 1097, in check_response_status
raise ex
solr.core.SolrException: HTTP code=400, reason=Bad Request
在 solr 跟踪方面我得到错误:
843169 [qtp1151734776-20] INFO org.apache.solr.update.processor.LogUpdateProcessor ? [collection1] webapp=/solr path=/update params={commit=true} {} 0 0
843170 [qtp1151734776-20] ERROR org.apache.solr.core.SolrCore ? org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id
schema.xml 文件位于 solr-4.4.0/example/solr/collection1/conf
我通过简单地在示例目录中运行 start.jar 来运行 solr。
知道我哪里出错了吗?