How to make atomic updates to solr using pysolr?

2019-07-21 18:22发布

I can't find a decent documentation on how to make updates to solr using pysolr.

标签: solr pysolr
3条回答
2楼-- · 2019-07-21 19:04

Using the same unique Solr ID and writing as usual (with solr.add) will overwrite/update the document. So, you can just write the new document setting the unique ID to match the old one that you want to update or you can pull the old document, do the change and gain make a new write using that updated document; since its the same ID you will still be overwriting/updating.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-07-21 19:12

You cannot currently make atomic updates to Solr using PySolr. There is a pull for it:

https://github.com/toastdriven/pysolr/pull/99

But it's not yet been merged. Last comment was less than a month ago, if you are interested I'd comment on it - or try to merge the code yourself if you feel up to it.

查看更多
Juvenile、少年°
4楼-- · 2019-07-21 19:12

As of November 2014 atomic updates are supported with pysolr. Here's a simple example:

url_solr = '''http://my.solr.com:8983/solr/mycore'''
solr = pysolr.Solr(url_solr)

doc = {'id':'rabid bananas', 'comment':'now half off!'}
solr.add([doc], fieldUpdates={'comment':'set'})
# the id 'rabid bananas' now has an updated comment
查看更多
登录 后发表回答