pysolr icon indicating copy to clipboard operation
pysolr copied to clipboard

Add "add if not exists" functionality to pysolr

Open Fikavec opened this issue 2 years ago • 1 comments

Pysolr add() function has a parameter "overwrite" with behavior:

  • if overwrite is "true" and document with unique id existing then Solr delete it and add to collection as new document. As a result, if after first document adds it has been updated, we lost thease changes.

  • if overwrite is "false", Solr just assume this document is unique and add to collection with same uniq id and other version field value. As a result we have many documents with same uniq id: <uniqueKey>id</uniqueKey> image

To solve this problem add to pysolr add/_update function boolean parameter createIfNotExists (or parameter to control _version_ ) as: if createIfNotExists: query_vars.append("_version_=-1")

In documentation https://solr.apache.org/guide/6_6/updating-parts-of-documents.html#UpdatingPartsofDocuments-OptimisticConcurrency

Fikavec avatar Jul 28 '21 20:07 Fikavec

That sounds like a useful addition if you want to send a pull-request

acdha avatar Jul 30 '21 18:07 acdha