--- title: "反向嵌套路径不是嵌套类型 – 如何解决此 Elasticsearch 异常" date: 2026-02-27 lastmod: 2026-02-27 description: "当在非嵌套字段上使用反向嵌套聚合时会发生此错误。Elasticsearch 要求该字段必须为嵌套类型才能执行此操作。" tags: ["聚合", "反向嵌套", "嵌套类型", "映射配置"] summary: " 版本: 6.8-8 简而言之,当在一个非嵌套字段上使用反向嵌套(reverse_nested)聚合时会发生此错误。Elasticsearch 要求该字段必须为嵌套类型才能执行此操作。要解决此问题,你可以在映射中将字段类型更改为嵌套类型,或使用不需要嵌套字段的其他聚合。或者,你可以重构数据以避免对反向嵌套聚合的需求。 日志上下文 # 日志"[reverse_nested] nested path [" + path + “] is not nested"的类名是 ReverseNestedAggregationBuilder.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: parentObjectMapper = context.getObjectMapper(path); if (parentObjectMapper == null) { return new ReverseNestedAggregatorFactory(name; true; null; context; parent; subFactoriesBuilder; metadata); } if (parentObjectMapper.isNested() == false) { throw new AggregationExecutionException("[reverse_nested] nested path [" + path + "] is not nested"); } } NestedScope nestedScope = context.nestedScope(); NestedObjectMapper nestedMapper = (NestedObjectMapper) parentObjectMapper; " --- > **版本:** 6.8-8 简而言之,当在一个非嵌套字段上使用反向嵌套(reverse_nested)聚合时会发生此错误。Elasticsearch 要求该字段必须为嵌套类型才能执行此操作。要解决此问题,你可以在映射中将字段类型更改为嵌套类型,或使用不需要嵌套字段的其他聚合。或者,你可以重构数据以避免对反向嵌套聚合的需求。 日志上下文 ----------- 日志"[reverse_nested] nested path [" + path + "] is not nested"的类名是[ReverseNestedAggregationBuilder.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java parentObjectMapper = context.getObjectMapper(path); if (parentObjectMapper == null) { return new ReverseNestedAggregatorFactory(name; true; null; context; parent; subFactoriesBuilder; metadata); } if (parentObjectMapper.isNested() == false) { throw new AggregationExecutionException("[reverse_nested] nested path [" + path + "] is not nested"); } } NestedScope nestedScope = context.nestedScope(); NestedObjectMapper nestedMapper = (NestedObjectMapper) parentObjectMapper; ```