python - 使用 python 用 solr 中的动态值更新字段值
问题描述
我有更新值的字典,我想使用 python 代码用 solr 中的动态值更新字段值。
基本上我正在使用以下逻辑从 tweepy 获取推文:
outtweets = [[
dict_1["favorite_count"]=tweet.favorite_count
dict_1["retweet_count"]=tweet.retweet_count
for idx, tweet in enumerate(all_tweets)]
但是favorite_count
,retweet_count
这个字段在每次更改时都是动态的。
下面已经存在的 Apache solr 数据/模式。
{
"favorite_count":0,
"retweet_count":16,
}
由于字段是动态的,我如何在 solr 中更新这个特定值?
解决方案
您可以使用 Solr 原子更新仅更新这两个字段。
import pysolr
solr = pysolr.Solr("http://localhost:8983/solr/collectionName")
solr.add({'id':1, 'favorite_count': {'set': 0}, 'retweet_count': {'set': 16}})
solr.commit()