ElascticsearchClient 8.5.3 (Java) cannot unblock index via client

Hi, everyone!
I'm trying to create a custom health check for Elasticsearch where its status is Down if an index is blocked (read-only, read-only-allow-delete, write) but I can't cover it with tests. This code doesn't work when the index is already blocked:

IndexSettings settings = new IndexSettings.Builder()
                .blocks(builder -> builder.readOnly(false)
                        .readOnlyAllowDelete(false)
                        .write(false))
esClient.indices().putSettings(builder -> builder.index(INDEX_NAME).settings(settings));

In the test, I change the settings to see that the health-check status is Down

IndexSettings settings = new IndexSettings.Builder()
            .blocks(builder -> builder.readOnly(true))
            .build();

esClient.indices().putSettings(builder -> builder.index(INDEX_NAME).settings(settings));

But I can't reverse this operation with readOnly(false) to reset the state and I'm wondering why? I'm having co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/indices.put_settings] failed: [cluster_block_exception] index [test_index] blocked by: [FORBIDDEN/5/index read-only (api)];

Can someone help with this, please?

Hi @Denko

My suggestion is that you close the index and perform the operation, that way it maybe works.

Thank you for the suggestion. But I can't close the index with the client either after I set it to read-only mode

I don't know if you already solved it but I did a test and I also couldn't reverse the operation.
The strange thing is that via devTools I can revert but not through the new java api client.

However it is possible to revert in another unusual way, using RestClient. Below is the code I made to reverse the operation.

    var json = "{\n"
        + "  \"index\": {\n"
        + "    \"blocks.read_only\": false\n"
        + "  }\n"
        + "}";
    Request request = new Request("PUT", "test/_settings");
    request.setJsonEntity(json);
    var response = ClientUtils.getRestClient().performRequest(request);
    var content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
    System.out.println(content);