0

I’m trying to execute the following line, but it throws an error (that I’m supposed to avoid by running the same code):

   es.indices.put_settings(index="demo_index", body={
        "blocks": {
            "read_only_allow_delete": "false"
        }
    })

Error: elasticsearch.exceptions.AuthorizationException: AuthorizationException(403, 'cluster_block_exception', 'blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];')

It I trigger the same query by using curl, it is sucessfully executed and I don’t have the error:

curl -XPUT 'localhost:9200/demo_index/_settings' -H 'Content-Type: application/json' -d '{ "index": { "blocks": { "read_only_allow_delete": "false" } } }'

I also tried to use "null" instead of "false", but I’m getting the same result. Any idea?

gal007
  • 6,911
  • 8
  • 47
  • 70

2 Answers2

2

I don't have enough reputation to add a comment, but have you tried wrapping the body parameter with index to match the curl command?

es.indices.put_settings(index="demo_index", body={
        "index": {
            "blocks": {
                "read_only_allow_delete": "false"
            }
        }
    })
kjr
  • 131
  • 4
1

With new API you can achieve this as :

import elasticsearch

def connect_elasticsearch():
    _es = None
    _es = elasticsearch.Elasticsearch([{'host': 'localhost', 'port': 9200}])
    if _es.ping():
        print('Yay Connect')
    else:
        print('Awww it could not connect!')
    return _es

es = connect_elasticsearch()

try:
    body = {"index.blocks.read_only_allow_delete": "false"}
    es_index_settings = es.indices.put_settings(index="demo_index",body=body)
except elasticsearch.ElasticsearchException as exp:
    print(exp)
Akhilesh Joshi
  • 288
  • 3
  • 13