--- title: "Top hits 聚合不能与时间序列聚合一起使用 - 如何解决此 Elasticsearch 异常" date: 2026-03-23 lastmod: 2026-03-23 description: "当在 Elasticsearch 中尝试在同一查询中同时使用 top hits 聚合和时间序列聚合时,会出现此错误。由于复杂性及潜在的性能问题,Elasticsearch 不支持这种组合。" tags: ["聚合", "Top hits聚合", "时间序列聚合", "异常处理", "查询优化"] summary: " 版本: 8.1-8.9 简而言之,当您在 Elasticsearch 中尝试在同一查询中同时使用 top hits 聚合和时间序列聚合时,会出现此错误。由于复杂性及潜在的性能问题,Elasticsearch 不支持这种组合。要解决此问题,您可以将这两种类型的聚合分离到不同的查询中。或者,您可以重新构建数据或查询,以避免同时需要两种类型的聚合。 日志上下文 # 日志 “Top hits aggregations cannot be used together with time series aggregations” 的类名是 TopHitsAggregatorFactory.java. 我们从 Elasticsearch 源代码中提取了以下内容,供寻求深入背景的人参考: AggregatorFactories.Builder subFactories; Mapmetadata ) throws IOException { super(name; context; parent; subFactories; metadata); if (context.isInSortOrderExecutionRequired()) { throw new AggregationExecutionException("Top hits aggregations cannot be used together with time series aggregations"); } this.from = from; this.size = size; this.explain = explain; this.version = version; " --- > **版本:** 8.1-8.9 简而言之,当您在 Elasticsearch 中尝试在同一查询中同时使用 top hits 聚合和时间序列聚合时,会出现此错误。由于复杂性及潜在的性能问题,Elasticsearch 不支持这种组合。要解决此问题,您可以将这两种类型的聚合分离到不同的查询中。或者,您可以重新构建数据或查询,以避免同时需要两种类型的聚合。 日志上下文 ----------- 日志 "Top hits aggregations cannot be used together with time series aggregations" 的类名是 [TopHitsAggregatorFactory.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供寻求深入背景的人参考: ```java AggregatorFactories.Builder subFactories; Mapmetadata ) throws IOException { super(name; context; parent; subFactories; metadata); if (context.isInSortOrderExecutionRequired()) { throw new AggregationExecutionException("Top hits aggregations cannot be used together with time series aggregations"); } this.from = from; this.size = size; this.explain = explain; this.version = version; ```