shishir
shishir

Reputation: 33

How to make atomic updates to solr using pysolr?

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

Upvotes: 3

Views: 4582

Answers (3)

Kwame
Kwame

Reputation: 757

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

Upvotes: 10

Hussein Ahmed
Hussein Ahmed

Reputation: 39

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.

Upvotes: 1

John Petrone
John Petrone

Reputation: 27487

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.

Upvotes: 1

Related Questions