出现这种问题,一般是索引文件损坏了,可能是内存不足,导致文件坏了,这个时候,按照以下步骤一步步排查可解决:

1、查看健康情况:

curl -XGET 'http://127.0.0.1:9200/_cluster/health?pretty=true'

ES 一启动就报:all shards failed_json

  最后一栏:active_shards_percent_as_number 的值,健康状态的值没有达到 100,现在才 50 多。

2、查看损坏索引:

curl -XGET 'http://127.0.0.1:9200/_cat/indices?v&pretty'

ES 一启动就报:all shards failed_json_02

  看最左边的 health 下面的状态颜色,应该都为  green 才对,现在有 yellow ,有些时候是 red 等

3、开始修复:

curl -H "Content-Type: application/json" -XPUT 'http://127.0.0.1:9200/_all/_settings' -d '
{
"index" : {
"number_of_replicas" : 0
}
}'

ES 一启动就报:all shards failed_json_03

 返回 {"acknowledged":true} 即修复好。

4、最后再查看健康状态:

ES 一启动就报:all shards failed_内存不足_04

 active_shards_percent_as_number 已恢复为 100 ,即可正常启动 es 了。

【最后:如果遇到还是不行,可以选择 delete 损坏的索引:】

curl -XDELETE  "http://127.0.0.1:9200/mongo*

mongo 这个索引值,看步骤二下的 index 值