0

我正在尝试执行以下行,但它会引发错误(我应该通过运行相同的代码来避免):

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

错误:elasticsearch.exceptions.AuthorizationException:AuthorizationException(403,'cluster_block_exception','被阻止:[FORBIDDEN/12/index 只读/允许删除(api)];')

如果我使用 curl 触发相同的查询,它已成功执行并且我没有错误:

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

我也尝试使用“null”而不是“false”,但我得到了相同的结果。任何想法?

4

2 回答 2

2

我没有足够的声誉来添加评论,但是您是否尝试过将body参数包装起来index以匹配 curl 命令?

es.indices.put_settings(index="demo_index", body={
        "index": {
            "blocks": {
                "read_only_allow_delete": "false"
            }
        }
    })
于 2019-03-22T11:08:44.980 回答
1

使用新的 API,您可以通过以下方式实现:

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)
于 2020-08-20T20:06:48.007 回答