pysolr
pysolr copied to clipboard
Add "add if not exists" functionality to pysolr
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>
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
That sounds like a useful addition if you want to send a pull-request