我有一个带有更新值的字典,我想使用python代码用solr中的动态值更新字段值。例如,我展示了 retweet_count
此字段在每次更改时都是动态的。
它不应该是多值字段。
代码:
try:
if res['retweet_count'] != tweets['retweet_count']:
print "retweet increased . . old retweets : ", res['retweet_count'], " new retweets : ", tweets['retweet_count']
res['retweet_count'] = tweets['retweet_count']
except KeyError:
print "retweet_count not in res"
res['retweet_count'] = tweets['retweet_count']
solr.add([res])
错误:
Traceback (most recent call last):
File "user.py", line 267, in <module>
get_all_tweets(x)
File "user.py", line 245, in get_all_tweets
solr.add({'set':[res]}) # ==> solr
File "/home//anaconda3/envs/TwitterINt/lib/python2.7/site-packages/pysolr.py", line 1050, in add
solrapi=solrapi,
File "/home//anaconda3/envs/TwitterINt/lib/python2.7/site-packages/pysolr.py", line 572, in _update
{"Content-type": "application/json; charset=utf-8"},
File "/home//anaconda3/envs/TwitterINt/lib/python2.7/site-packages/pysolr.py", line 463, in _send_request
raise SolrError(error_message % (resp.status_code, solr_message))
pysolr.SolrError: Solr responded with an error (HTTP 400): [Reason: ERROR: [doc=1059346579209936896] Error adding field 'retweet_count'='0' msg=Multiple values encountered for non multiValued copy field retweeted_count: 0]
1条答案
按热度按时间x7yiwoj41#
您需要定义字段
retweet_count
在里面schema.xml
作为multiValued="true"
.这将帮助您解决错误。
您的字段定义如下所示。