python - key 错误 : 'id' when trying to index documents to Solr using sunburnt

标签 python solr sunburnt

我正在尝试使用 sunburnt 将一些文本文件索引到 Solr。下面是我的代码

solr_url = "http://localhost:8983/solr"      
h = httplib2.Http(cache="/var/tmp/solr_cache")    
solr_instance = sunburnt.SolrInterface(url=solr_url, http_connection=h)

for url,title, webpage in webpages: 
html_id = hashlib.md5(url).hexdigest()
doc = {"id":html_id, "content":webpage, "title":title}  
solr_instance.add(doc)

try:
    solr_instance.commit()
except:
      print "Could not Commit Changes to Solr, check the log files."
else:
      print "Successfully committed changes"

但是当我运行这个时,我收到以下错误。

  File "/Users/ananya/Desktop/dbms project/code/extractText/ExtractText.py", line 94, in index_to_Solr
    solr_instance = sunburnt.SolrInterface(url=solr_url, http_connection=h)

  File "/Users/ananya/anaconda/lib/python2.7/site-packages/sunburnt/sunburnt.py", line 166, in __init__
    self.init_schema()

  File "/Users/ananya/anaconda/lib/python2.7/site-packages/sunburnt/sunburnt.py", line 177, in init_schema
    self.schema = SolrSchema(schemadoc, format=self.format)

  File "/Users/ananya/anaconda/lib/python2.7/site-packages/sunburnt/schema.py", line 417, in __init__
    if self.unique_key else None

KeyError: 'id'

我对 Solr 很陌生。请帮我。我需要对架构文件进行任何更改吗?如果是,请告诉我如何做。

谢谢。

最佳答案

如果您使用 Solr 4.8 或更高版本,则这是 bug against sunburnt 0.6 .

The fork of sunburnt by arafalov 有一个补丁为我修复了这个问题。

尝试:

git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caada3be8aada3bea2bfa8e4a9a5a7" rel="noreferrer noopener nofollow">[email protected]</a>:arafalov/sunburnt.git
cd sunburnt
python setup.py install # optionally with --user

关于python - key 错误 : 'id' when trying to index documents to Solr using sunburnt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165407/

相关文章:

python - 如何实现每个工作线程同步以避免与 Celery 上的信号连接的方法出现竞争条件?

Python:谷歌驱动器身份验证

java - Solr 对存储的数据应用过滤器

search - Solr 文档的频繁更新 - 效率/可扩展性问题

linux - 如何在 Windows 操作系统中为 Jetty 7 添加用户

python - Solr,晒伤(python)和突出显示: how-to?

python - 使用 Sunburnt+Solr 创建动态大小的 OR 查询

python - Sunburnt solr 通配符 * :*

python - from twilio.rest import Client 没有名为ordered_dict 的模块错误

python - Django REST API 模板DoesNotExist Apache