Elasticsearch 的切片数是如何根据分片数计算的?

How is number of Elasticsearch number of slices are calculated based on the number of shards?

我使用的是 Elasticsearch 版本 elasticsearch-7.13.4。我在互联网上找不到任何准确的答案。有什么公式吗?

底层概念称为 "sliced scroll",与分片数量无关。来自链接文档:

By default the splitting is done on the shards first and then locally on each shard using the _id field with the following formula: slice(doc) = floorMod(hashCode(doc._id), max) For instance if the number of shards is equal to 2 and the user requested 4 slices then the slices 0 and 2 are assigned to the first shard and the slices 1 and 3 are assigned to the second shard.

但是,当使用automatic slicing(即slices=auto)时,Elasticsearch 将选择分片数作为切片数

Setting slices to auto will let Elasticsearch choose the number of slices to use. This setting will use one slice per shard, up to a certain limit. If there are multiple sources, it will choose the number of slices based on the index or backing index with the smallest number of shards.

Query performance is most efficient when the number of slices is equal to the number of shards in the index. [...] Setting slices higher than the number of shards generally does not improve efficiency and adds overhead.