LoginSignup
6
3

More than 3 years have passed since last update.

Elasticsearch > index [foo_index] blocked by

Posted at

Macのローカル環境のElasticsearchにデータ追加時に、cluster_block_exceptionが表示された件

現象

Elasticsearchにデータを追加しようとした時に、書き込みエラーが表示された

データ追加

$ curl --include -XPOST "http://localhost:9200/foo_index/_doc" \
-H 'Content-Type: application/json' \
-d '{
  "user": "peke",
  "message": "this message."
}'

データの追加時のレスポンス

{
    "error": {
        "root_cause": [
            {
                "type": "cluster_block_exception",
                "reason": "index [foo_index] blocked by: [TOO_MANY_REQUESTS/12/disk usage exceeded flood-stage watermark, index has read-only-allow-delete block];"
            }
        ],
        "type": "cluster_block_exception",
        "reason": "index [foo_index] blocked by: [TOO_MANY_REQUESTS/12/disk usage exceeded flood-stage watermark, index has read-only-allow-delete block];"
    },
    "status": 429
}

原因

Elasticsearchの設定を確認

$ curl --include -XGET "http://localhost:9200/foo_index/_settings?pretty"

{
  "foo_index" : {
    "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "blocks" : {
          "read_only_allow_delete" : "true"
        },
        "provided_name" : "foo_index",
        "creation_date" : "1601874837243",
        "number_of_replicas" : "1",
        "uuid" : "vNNFrvi_R3e6xpFXS3Xmqg",
        "version" : {
          "created" : "7090299"
        }
      }
    }
  }
}

"read_only_allow_delete" : "true" になっている。
読み取り専用モードになっているのが原因のもよう

以下のページにも書いてあったが、空きディスク容量が5%未満の場合、読み取り専用モードになるもよう

How to fix Elasticsearch 'FORBIDDEN/12/index read-only' - Today I Learned

By default, Elasticsearch installed with homebrew on Mac OS goes into read-only mode when you have less than 5% of free disk space. If you see errors similar to this:

デフォルトでは、Mac OSにhomebrewをインストールしたElasticsearchは、空きディスク容量が5%未満の場合、読み取り専用モードになります。

ディスクを確認

スクリーンショット 2020-10-05 16.08.14.png

(5%未満かというと微妙だが)たしかにディスク残量は少なくなっていた。

HDDの残量を増やして再度、設定を確認

$ curl --include -XGET "http://localhost:9200/foo_index/_settings?pretty"

{
    "foo_index": {
        "settings": {
            "index": {
                "creation_date": "1601879846599",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "pZXw3Ng7SeGZym9ORrkKaQ",
                "version": {
                    "created": "7090299"
                },
                "provided_name": "foo_index"
            }
        }
    }
}

blocksが消えました!!

再度データ追加

データ追加

$ curl --include -XPOST "http://localhost:9200/foo_index/_doc" \
-H 'Content-Type: application/json' \
-d '{
  "user": "peke",
  "message": "this message."
}'

データの追加時のレスポンス

{
    "_index": "foo_index",
    "_type": "_doc",
    "_id": "-uCZ93QB4SFaJHY-3iHL",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 0,
    "_primary_term": 2
}

データ追加ができました

追加の結果確認

$ curl --include -XGET "http://localhost:9200/foo_index/_doc/9xNyi3MBhHaU2qi75ayU?pretty"

{
    "_index": "foo_index",
    "_type": "_doc",
    "_id": "--Ca93QB4SFaJHY-aCFx",
    "_version": 2,
    "_seq_no": 2,
    "_primary_term": 2,
    "found": true,
    "_source": {
        "user": "peke",
        "message": "this message."
    }
}
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3