Python Client - unable to remove "read_only" block

When using the official Python client, I can't seem to find a way to change an index to normal "read-write" status once it's been marked "read_only".

This function works fine to go from read-write to read_only, but I was unable to identify any method to reverse it.

I can accomplish this in curl with something like the following:
curl -s -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -X PUT http://localhost:9200/my-index-2020.09/_settings -d '{ "index": { "blocks.read_only": false } }'

Thanks for any pointers you might have on this one!

For added context, this is what I have tried so far.

>>> es.indices.add_block(index='name', block="read_only")
{'acknowledged': True, 'shards_acknowledged': True, 'indices': [{'name': 'name', 'blocked': True}]}
>>>  es.indices.put_settings(index=name', body='{"blocks": { "read_only": true } }')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/client/", line 301, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/client/", line 811, in put_settings
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/", line 458, in perform_request
    raise e
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/", line 426, in perform_request
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/connection/", line 287, in perform_request
    self._raise_error(response.status, raw_data)
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/connection/", line 338, in _raise_error
    status_code, error_message, additional_info
elasticsearch.exceptions.AuthorizationException: AuthorizationException(403, 'cluster_block_exception', 'index [name] blocked by: [FORBIDDEN/5/index read-only (api)];')

However, the following works at a bash prompt:

curl -s -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -X PUT http://localhost:9200/name/_settings -d '{ "index": { "blocks.read_only": false } }'
{"acknowledged": true}

At a guess, we didn't allow that because this sort of action is typically an admin level one only, not something you'd want to give to a client.

Hmm, ok. Curious why setting the read-only would be supported but not the reverse. Especially since the action can be done via curl. (Suggesting to me that the python client is returning the denial rather than ES itself, but I admit that's speculation.)

I'm kind of hoping not to write a python script that can do everything except reverting to R-W, which has to be done via a subprocess call to curl.

I guess a better way to ask this, is:
Does this sound like an issue to file for a missing comparative feature within the Python client?

Yeah, I would suggest that'd be worth raising.

1 Like

Thanks, Mark - I appreciate it. For awareness/future searches, the issue is here: Cannot remove `read_only` block on an index · Issue #1788 · elastic/elasticsearch-py · GitHub

We were able to solve this issue, there was a typo in the request using the Python client attempting to set the blocks.read_only setting instead of the full index.blocks.read_only setting. Combine that with Elasticsearch favoring raising the "this index is read-only" error over the "this setting doesn't exist" error.

1 Like

After a tiny bit more digging, this may actually be a bug. Detailed in this issue: Unblocking an index using 'blocks.read_only: false' doesn't work like 'index.blocks.read_only: false' · Issue #80383 · elastic/elasticsearch · GitHub

1 Like

Thanks again for your help on this. Implemented a fix and seems to be working as intended. Much appreciated!

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