# ElascticsearchClient 8.5.3 (Java) cannot unblock index via client

**URL:** <https://discuss.elastic.co/t/elascticsearchclient-8-5-3-java-cannot-unblock-index-via-client/323812>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 24, 2023, 11:23am UTC](https://discuss.elastic.co/t/elascticsearchclient-8-5-3-java-cannot-unblock-index-via-client/323812 "2023-01-24T11:23:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denko](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@Denko](https://discuss.elastic.co/u/Denko)\
**Post date:** [January 24, 2023, 11:23am UTC](https://discuss.elastic.co/t/elascticsearchclient-8-5-3-java-cannot-unblock-index-via-client/323812/1 "2023-01-24T11:23:13Z")

</div>

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:

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [January 24, 2023, 11:51am UTC](https://discuss.elastic.co/t/elascticsearchclient-8-5-3-java-cannot-unblock-index-via-client/323812/2 "2023-01-24T11:51:34Z")

</div>

Hi @Denko

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

---

<div class="post-metadata">

**Author:** ![Denko](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@Denko](https://discuss.elastic.co/u/Denko)\
**Post date:** [January 24, 2023, 12:19pm UTC](https://discuss.elastic.co/t/elascticsearchclient-8-5-3-java-cannot-unblock-index-via-client/323812/3 "2023-01-24T12:19:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [January 24, 2023, 8:42pm UTC](https://discuss.elastic.co/t/elascticsearchclient-8-5-3-java-cannot-unblock-index-via-client/323812/4 "2023-01-24T20:42:05Z")

</div>

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.

```auto
    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);

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 21, 2023, 8:42pm UTC](https://discuss.elastic.co/t/elascticsearchclient-8-5-3-java-cannot-unblock-index-via-client/323812/5 "2023-02-21T20:42:13Z")

</div>

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