当尝试将文档发布到Elasticsearch时,我得到了这个错误:

cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)];

我还在Elasticsearch日志中看到了这样的消息:

flood stage disk watermark [95%] exceeded ... all indices on this node will marked read-only

当前回答

仅使用以下命令更改设置在我的环境中不起作用:

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

我还必须运行强制合并API命令:

curl -X POST "localhost:9200/my-index-000001/_forcemerge?pretty"

参考:强制合并API

其他回答

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

FROM

https://techoverflow.net/2019/04/17/how-to-fix-elasticsearch-forbidden-12-index-read-only-allow-delete-api/

当您的机器磁盘空间不足时,通常会观察到此错误。 要避免此错误消息所遵循的步骤

Resetting the read-only index block on the index: $ curl -X PUT -H "Content-Type: application/json" http://127.0.0.1:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}' Response ${"acknowledged":true} Updating the low watermark to at least 50 gigabytes free, a high watermark of at least 20 gigabytes free, and a flood stage watermark of 10 gigabytes free, and updating the information about the cluster every minute Request $curl -X PUT "http://127.0.0.1:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d' { "transient": { "cluster.routing.allocation.disk.watermark.low": "50gb", "cluster.routing.allocation.disk.watermark.high": "20gb", "cluster.routing.allocation.disk.watermark.flood_stage": "10gb", "cluster.info.update.interval": "1m"}}' Response ${ "acknowledged" : true, "persistent" : { }, "transient" : { "cluster" : { "routing" : { "allocation" : { "disk" : { "watermark" : { "low" : "50gb", "flood_stage" : "10gb", "high" : "20gb" } } } }, "info" : {"update" : {"interval" : "1m"}}}}}

运行这两个命令后,必须再次运行第一个命令,以使索引不会再次进入只读模式

ELK团队的一个很好的指南:

https://www.elastic.co/guide/en/elasticsearch/reference/master/disk-usage-exceeded.html

我用ELK 7.x就能做到

默认情况下,当可用磁盘空间小于5%时,安装的Elasticsearch将进入只读模式。如果你看到类似这样的错误:

Elasticsearch:运输:运输::错误::禁止:[403] {"错误":{“root_cause”:[{“类型”:“cluster_block_exception”,“原因”:“封锁 [FORBIDDEN/12/index read-only / allow delete . (api)];“}],”类型”:“cluster_block_exception”:“被”、“原因: [FORBIDDEN/12/index read-only / allow delete (api)];“}”状态”:403}

或者在/usr/local/var/log/elasticsearch.log中可以看到类似的日志:

泛洪级磁盘水位[95%]超过上 [nCxquc7PTxKvs6hLkfonvg] [nCxquc7] [/ usr /地方/ var / lib / elasticsearch /节点/ 0] Free: 15.3gb[4.1%],该节点上的所有索引将被标记为只读

可以通过以下命令进行修复:

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

仅使用以下命令更改设置在我的环境中不起作用:

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

我还必须运行强制合并API命令:

curl -X POST "localhost:9200/my-index-000001/_forcemerge?pretty"

参考:强制合并API