如何撤销将Elasticsearch索引设置为只读?

htzpubme  于 2022-12-22  发布在  ElasticSearch
关注(0)|答案(6)|浏览(330)

因此,我刚刚将其中一个索引设置为只读,现在想删除它。
要将其设置为只读:

PUT my_index/_settings
{ "index": { "index.blocks.read_only" : true } }

当我试图删除它时,我得到了这样的回应:

ClusterBlockException[blocked by: [FORBIDDEN/5/index read-only (api)];]

然后我尝试将索引设置为readonlyfalse:

PUT my_index/_settings
{ "index": { "index.blocks.read_only" : false } }

但是这会给出与上面相同的错误信息,那么如何将readonly设置回false呢?

xjreopfe

xjreopfe1#

答案太老了,所以我也会添加一个弹性答案-6+:

PUT /[_all|<index-name>]/_settings
{
  "index.blocks.read_only_allow_delete": null
}

https://www.elastic.co/guide/en/elasticsearch/reference/6.x/disk-allocator.html
仅供参考(用于上下文):由于磁盘空间不足,我遇到了只读索引,并从logstash收到错误消息:

...retrying failed action with response code: 403 ({"type"=>"cluster_block_exception", "reason"=>"blocked"

ElasticSearch:
(美国石油API)];]

kg7wmglp

kg7wmglp2#

es index设置为只读的正确方法是

PUT your_index/_settings
{
  "index": {
    "blocks.read_only": true
  }
}

true更改为false以撤消它。
使用设置非动态设置

{
      "index": {
        "blocks.read_only": false
      }
    }

我认为这不是你的意图。而且我认为你应该在第一次操作时看到一个错误,因为非动态设置只能在close indices上更新。
运行

POST your_index/_close

然后尝试改变它。

ckocjqey

ckocjqey3#

curl -X PUT "localhost:9200/_all/_settings" -H 'Content-Type: application/json' -d'{ "index.blocks.read_only" : false } }'
1mrurvl1

1mrurvl14#

在ElasticSearch(ES)的2.x版本中,您必须执行以下操作

PUT your_index/_settings

{
  "index": {
    "blocks": {
      "write": "false",
      "read_only": "false"
    }
  }
}

当在内部将read_only的索引设置为true时,ES也会将write更改为true,而仅将read_only恢复为false仍不允许更新索引,因此必须显式更新write设置。

qnzebej0

qnzebej05#

如果您安装了Kibana,您可以转到您的Kibana URL:

Management (Left pane) -> Elasticseach Index Management -> Select your Index -> Edit Settings

然后更新:

"index.blocks.read_only_allow_delete": "false"

此外,要在kibana上全局设置它,您可以转到dev tools(左窗格)并提出以下请求:

PUT _settings
{
  "index": {
    "blocks": {
      "read_only_allow_delete": "false"
    }
  }
}
s6fujrry

s6fujrry6#

对于6.x,要获取设置:

curl elasticsearch-sc:9200/_settings?pretty

要使索引/簇可写:

curl -XPUT -H "Content-Type: application/json" \
 http://elasticsearch-sc:9200/_all/_settings \
   -d '{"index.blocks.read_only_allow_delete": null}'

相关问题