我应该在开发和 CI 环境中使用 Elasticsearch 多少分片?

How many shards should I use with Elasticsearch on a dev & CI environment?

默认情况下,Elasticsearch 配置为从 5 个分片开始。

是否有理由在本地(在我的开发机器上)和持续集成服务器(用于集成测试)上使用 5 个分片?使用 1 更好吗?

显然我不关心那些情况下的可扩展性,我只想要最简单的设置。

最简单的设置是 1 个主分片,0 个副本。

如果您只有一个节点并且副本数 >0,它将始终为 yellow。本身不是问题,但不需要这些。

如果你想用那个分片测试搜索响应时间,例如,1 是否足够或你需要更多取决于一些因素。例如,最简单的经验法则是让分片不超过 30-50GB。但这个数字也取决于因素。

所以,我会说,如果您有一个节点,请从 1 个主节点和 0 个副本开始。如果那个主节点太多 "large",考虑拥有更多的主节点(每个分片将完成一部分工作,每个分片将使用一个核心 CPU 进行搜索)。

一旦您使用特定的分片配置推送了一些数据,您就无法在不重新索引数据的情况下设置不同数量的分片。所以我的猜测是,elasticsearch 的默认配置是为了让您可以轻松地将集群扩展到 5 个节点(然后每个节点获得一个分片)。

来自 elasticsearch documentation:

A new index in Elasticsearch is allotted five primary shards by default. That means that we can spread that index out over a maximum of five nodes, with one shard on each node. That’s a lot of capacity, and it happens without you having to think about it at all!