Elasticsearch noop update response not deserializable

426 views Asked by At

My scripted update produces the following noop response since the condition was not met:

/my_idx/_update/my_doc_id

{
    "_index": "my_idx",
    "_type": "_doc",
    "_id": "my_doc_id",
    "_version": 4,
    "result": "noop",
    "_shards": {
        "total": 0,
        "successful": 0,
        "failed": 0
    }
}

However, this response could not be deserialized to UpdateResponse<TDocument> by the elasticsearch-java client due to the constraints imposed by its super constructor in WriteResponseBase, specifically around primaryTerm and seqNo, which are clearly missing in a noop update response:

    protected WriteResponseBase(AbstractBuilder<?> builder) {

        this.id = ApiTypeHelper.requireNonNull(builder.id, this, "id");
        this.index = ApiTypeHelper.requireNonNull(builder.index, this, "index");
        this.primaryTerm = ApiTypeHelper.requireNonNull(builder.primaryTerm, this, "primaryTerm");
        this.result = ApiTypeHelper.requireNonNull(builder.result, this, "result");
        this.seqNo = ApiTypeHelper.requireNonNull(builder.seqNo, this, "seqNo");
        this.shards = ApiTypeHelper.requireNonNull(builder.shards, this, "shards");
        this.type = builder.type;
        this.version = ApiTypeHelper.requireNonNull(builder.version, this, "version");
        this.forcedRefresh = builder.forcedRefresh;

    }

The version of my Java client is 8.4.2, while the server instance version is 7.2.0. I've already had to do some hacks to get these two versions to work together. I am wondering if these missing fields were indeed optional in 7.2.0. Unfortunately, I have no way of checking because they only have tags from 7.15.0 in Github.

Is there any workaround, or is catching the resulting exception and handling it (hoping it's because of the noop) the only way to get it to work?

1

There are 1 answers

0
Briomkez On BEST ANSWER

The inconsistencies between the Update response for Noop and really updated documents have been reported in this github issue. This has been resolved with this PR which have been released in version 7.4.0 of Elasticsearch, as confirmed in the Release notes of that version.

That being said, I think the cleanest solution would be to either update Elasticsearch (consider that the v. 7.2.0 is more than 2 years old) to a version >= 7.4.0 or to add the detect_noop flag to your requests. Bare in mind that this forces the version number of the document to be always be updated even thought there is actually no update of the document itself.

Moreover, I don't think there is any guarantee that a REST client in version 8 should work with Elasticsearch 7.x let alone version 7.2. The Elasticsearch Server Compatibility Policy states clearly that the client is forward-compatible. But you are trying to use it in a backward-compatible manner.