On 12/18/23 21:42, Saksham Gupta wrote:
I have written a small script in python to delete a product from solr cloud
collection on the basis of unique id, _route_ and _version_.

I have extracted the exact values of unique id, _route_ and _version_ from
solr index and used them to delete the product. But my script gives an
error which indicates that the _version_ I used is incorrect. The error
message looks like:

"msg":"Async exception during distributed update: Error from server at
http://solr_ip:port/solr/collection_name/: null\n\n\n\nrequest:
http://solr_ip:port/solr/collection_name/\nRemote error message: version
conflict for {unique id} expected=1784635392440402000
actual=1784635392440401920",

     "code":409}}

1. How could this be the case where actual _version_ is different from the
one visible on querying.

Is there anything else running that might update the document between the query request and the delete request?

Do you possibly have the same uniqueKey value in more than one shard?

If either of those conditions is true, then automatically generated fields like _version_ are subject to change.

2. How to get the actual _version_ of a document?

Just do any query that would match that document and the _version_ field should be in the search results. If you have documents with the same uniqueKey value in multiple shards, then which document gets returned cannot be predicted. Solr will eliminate duplicates when returning results so there is only one document for each uniqueKey field value.

3. Any other ways to delete the solr document using _version_?

When using the implicit router, if you simply use deleteById and give it the value in the uniqueKey field, I am reasonably certain that the delete request is sent to all shards so it won't matter what shard it's in or what _version_ it has.

Thanks,
Shawn

Reply via email to