How to make atomic updates to solr using pysolr?

2019-07-21 18:21发布

问题:

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

回答1:

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.



回答2:

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


回答3:

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.



标签: solr pysolr