Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "add if not exists" functionality to pysolr #367

Open
Fikavec opened this issue Jul 28, 2021 · 1 comment
Open

Add "add if not exists" functionality to pysolr #367

Fikavec opened this issue Jul 28, 2021 · 1 comment

Comments

@Fikavec
Copy link

Fikavec commented Jul 28, 2021

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

@acdha
Copy link
Collaborator

acdha commented Jul 30, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants