Java client : VersionConflictEngineException changed to ElasticsearchException?


#1

Hi everyone !
We recently moved from version 2.x to 6.x and we noticed one unexcepted impact on our java code.
We were catching a VersionConflictEngineException like this :

BulkResponse bulkReponses = bulkRequest.execute().actionGet();
if (bulkReponses.hasFailures()) {
    BulkItemResponse[] items = bulkReponses.getItems();

    for (BulkItemResponse r : items) {
        if (r.isFailed()) {
            BulkItemResponse.Failure f = r.getFailure();
            if (f.getCause() instanceof VersionConflictEngineException) {
                // do something
               ...
            }
        }
    }

But after upgrading, f.getCause() return a ElasticsearchException and we have to read f.getCause().getMessage() to search for "type=version_conflict_engine_exception".
Is the change of the exception type normal ?
I noticed that, in this case, RestStatus is equal to 409 (CONFLICT). Is "version conflict" the only possible conflict or can other type of conflict used this status too ?
I would like to find a reliable and better way to check if it's a version conflict exception than searching for a string in the exception message.
Thanks for your help !


(Luca Cavanna) #2

Hi,
quick question, have you moved your client code from Java API to the high-level REST client by any chance?

I would definitely check at the RestStatus, I am pretty sure that 409 in that case is a version conflict.

Cheers
Luca


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.