原文网址:ElasticSearch--解决this action would add [5] total shards, but this cluster currently has [1000]/[1000_IT利刃出鞘的博客-CSDN博客
简介本文介绍ElasticSearch分片数量导致的异常的解决方案。
异常的日志为:this action would add [5] total shards, but this cluster currently has [1000]/[1000
问题描述项目里SkyWalking使用ES来存数据,但今天我查看日志时没有今天的数据,只有昨天的,于是我查看SkyWalking的日志(logs/skywalking-oap-server.log),发现如下结果:
[4532]: index [sw_segment-20211201], type [_doc], id [1c8b09ece71a45bd8de74e27a74a6bf6.167.16383242084776012], message [ElasticsearchException[Elasticsearch exception [type=validation_exception, reason=Validation Failed: 1: this action would add [5] total shards, but this cluster currently has [1000]/[1000] maximum shards open;]]] [4533]: index [sw_log-20211201], type [_doc], id [34a07ac188a8433e865a3bbabb74673a], message [ElasticsearchException[Elasticsearch exception [type=validation_exception, reason=Validation Failed: 1: this action would add [5] total shards, but this cluster currently has [1000]/[1000] maximum shards open;]]] [4534]: index [sw_segment-20211201], type [_doc], id [1c8b09ece71a45bd8de74e27a74a6bf6.167.16383242085016022], message [ElasticsearchException[Elasticsearch exception [type=validation_exception, reason=Validation Failed: 1: this action would add [5] total shards, but this cluster currently has [1000]/[1000] maximum shards open;]]] [4535]: index [sw_segment-20211201], type [_doc], id [1c8b09ece71a45bd8de74e27a74a6bf6.167.16383242085336030], message [ElasticsearchException[Elasticsearch exception [type=validation_exception, reason=Validation Failed: 1: this action would add [5] total shards, but this cluster currently has [1000]/[1000] maximum shards open;]]] [4536]: index [sw_segment-20211201], type [_doc], id [1c8b09ece71a45bd8de74e27a74a6bf6.167.16383242085436040], message [ElasticsearchException[Elasticsearch exception [type=validation_exception, reason=Validation Failed: 1: this action would add [5] total shards, but this cluster currently has [1000]/[1000] maximum shards open;]]]
其异常信息都是:this action would add [5] total shards, but this cluster currently has [1000]/[1000] maximum shards open;
原因分析ES7.x默认分片只有1000个,目前已经用完了,导致已经没法创建新的索引了。
解决方案解决方法就是提高ES的分片数量。
方法1:控制台
PUT /_cluster/settings
{
"persistent": {
"cluster": {
"max_shards_per_node":10000
}
}
}
persistent:永久生效,transient:临时生效。
方法2:CURL命令
curl --location --request PUT 'http://127.0.0.1:9200/_cluster/settings'
--header 'Content-Type: application/json'
--data '{"persistent":{"cluster":{"max_shards_per_node":10000}}}'
persistent:永久生效,transient:临时生效。
其他方法
有人说可以修改配置文件(elasticsearch.yml),添加下边一行
cluster.max_shards_per_node: 10000
但我测试发现 ,没有生效。我通过GET /_cluster/settings?pretty查看,返回结果如下:
{
"persistent": {},
"transient": {}
}
我的ES版本为:7.15.0
查看是否生效GET /_cluster/settings?pretty
结果
{
"persistent": {
"cluster": {
"max_shards_per_node": "10000"
}
},
"transient": {}
}
其他网址
this cluster currently has [1946]/[1000] maximum shards open_luoqinglong的专栏-CSDN博客


![ElasticSearch--解决this action would add [5] total shards, but this cluster currently has [1000]/[1000 ElasticSearch--解决this action would add [5] total shards, but this cluster currently has [1000]/[1000](http://www.mshxw.com/aiimages/31/630229.png)
