一、Elasticsearch报错
[2020-05-03T11:23:43,758][WARN ][o.e.x.m.e.l.LocalExporter] [node-1] unexpected error while indexing monitoring document
org.elasticsearch.xpack.monitoring.exporter.ExportException: org.elasticsearch.common.ValidationException: Validation Failed: 1: this action would add [1] total shards, but this cluster currently has [1000]/[1000] maximum shards open
二、原因
ElasticSearch 7.x 如果没有配置 cluster.max_shards_per_node
,默认的分片数是1000。
三、方法
1、控制台
PUT /_cluster/settings
{
"persistent": {
"cluster": {
"max_shards_per_node":10000
}
}
}
2、修改配置文件
# vim elasticsearch.yml
cluster.max_shards_per_node: 10000
3、shell命令
curl -X PUT "192.168.1.107:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{
"persistent" : {
"cluster.max_shards_per_node" : "5000"
}
}
'
persistent:永久生效,
transient:临时生效
四、优化实践
如果现在你的场景是分片数不合适了,但是又不知道如何调整,那么有一个好的解决方法就是按照时间创建索引,然后进行通配查询。如果每天的数据量很大,则可以按天创建索引,如果是一个月积累起来导致数据量很大,则可以一个月创建一个索引。如果要对现有索引进行重新分片,则需要重建索引。
对于分片数的大小,业界一致认为分片数的多少与内存挂钩,认为 1GB 堆内存对应 20-25 个分片。因此,具有30GB堆的节点最多应有600个分片,但是越低于此限制,您可以使其越好。而一个分片的大小不要超过50G,通常,这将有助于群集保持良好的运行状况。