--- title: "无法收集超过指定数量的桶 - 如何解决此 Elasticsearch 异常" date: 2026-02-23 lastmod: 2026-02-23 description: "当 Elasticsearch 尝试收集超过系统限制的桶数量时,会抛出'Can't collect more than'异常。本文介绍该错误的原因和解决方案。" tags: ["Elasticsearch异常", "聚合查询", "桶聚合", "内存限制", "BucketsAggregator"] summary: "版本: 7.9-7.15 简要说明 # 简而言之,当 Elasticsearch 尝试收集超过系统设定限制的桶(buckets)数量时,就会发生此错误。这可能是由于存在大量的索引,每个索引又包含多个分片导致的。 要解决此问题,你可以通过调整 Elasticsearch 配置中的 action.search.shard_count.limit 设置来增加限制。或者,你可以通过合并索引或减少每个索引的分片数量来减少分片总数。 日志上下文 # 日志 “Can’t collect more than [” 的类名是 BucketsAggregator.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些需要深入了解上下文的用户参考: final long bucketCount = bucketOrds.bucketsInOrd(owningBucketOrds[ordIdx]); bucketsInOrd[ordIdx] = (int) bucketCount; totalOrdsToCollect += bucketCount; } if (totalOrdsToCollect > Integer.MAX_VALUE) { throw new AggregationExecutionException("Can't collect more than [" + Integer.MAX_VALUE + "] buckets but attempted [" + totalOrdsToCollect + "]"); } long[] bucketOrdsToCollect = new long[(int) totalOrdsToCollect]; int b = 0; for (int ordIdx = 0; ordIdx < owningBucketOrds." --- > **版本:** 7.9-7.15 ## 简要说明 简而言之,当 Elasticsearch 尝试收集超过系统设定限制的桶(buckets)数量时,就会发生此错误。这可能是由于存在大量的索引,每个索引又包含多个分片导致的。 要解决此问题,你可以通过调整 Elasticsearch 配置中的 `action.search.shard_count.limit` 设置来增加限制。或者,你可以通过合并索引或减少每个索引的分片数量来减少分片总数。 ## 日志上下文 日志 "Can't collect more than [" 的类名是 `BucketsAggregator.java`。我们从 Elasticsearch 源代码中提取了以下内容,供那些需要深入了解上下文的用户参考: ```java final long bucketCount = bucketOrds.bucketsInOrd(owningBucketOrds[ordIdx]); bucketsInOrd[ordIdx] = (int) bucketCount; totalOrdsToCollect += bucketCount; } if (totalOrdsToCollect > Integer.MAX_VALUE) { throw new AggregationExecutionException("Can't collect more than [" + Integer.MAX_VALUE + "] buckets but attempted [" + totalOrdsToCollect + "]"); } long[] bucketOrdsToCollect = new long[(int) totalOrdsToCollect]; int b = 0; for (int ordIdx = 0; ordIdx < owningBucketOrds.length; ordIdx++) { ```