--- title: "父字段在单类型索引上已禁用 - 如何解决此 Elasticsearch 异常" date: 2026-01-05 lastmod: 2026-01-05 description: "在 Elasticsearch 6.x 或更高版本中尝试使用 [_parent] 字段时会报此错误,这是因为这些版本已取消对每个索引多个类型的支持。本文介绍如何使用 join 字段来建模父子关系。" tags: ["父字段", "单类型索引", "父子关系", "映射异常"] summary: " 版本: 6.8-6.8 简要来说,当您尝试在 Elasticsearch 6.x 或更高版本中使用 [_parent] 字段时会出现此错误,这些版本已取消对每个索引多个类型的支持。[_parent] 字段用于在同一索引中不同类型的文档之间建立父子关系。要解决此问题,您可以使用 “join” 字段来建模父子关系,或者重组数据结构以避免对父子关系的需求。或者,如果父子关系不是至关重要的,您可以为每个类型使用单独的索引。 日志上下文 # 日志 “[_parent] field is disabled on indices with a single type.” 的类名是 ParentFieldMapper.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入背景的人参考: } @Override public ParentFieldMapper build(BuilderContext context) { if (context.indexCreatedVersion().onOrAfter(Version.V_6_5_0)) { throw new MapperParsingException("[_parent] field is disabled on indices with a single type. " + "Use a [join] field instead."); } if (parentType == null) { throw new MapperParsingException("[_parent] field mapping must contain the [type] option"); } " --- > **版本:** 6.8-6.8 简要来说,当您尝试在 Elasticsearch 6.x 或更高版本中使用 [_parent] 字段时会出现此错误,这些版本已取消对每个索引多个类型的支持。[_parent] 字段用于在同一索引中不同类型的文档之间建立父子关系。要解决此问题,您可以使用 "join" 字段来建模父子关系,或者重组数据结构以避免对父子关系的需求。或者,如果父子关系不是至关重要的,您可以为每个类型使用单独的索引。 日志上下文 ----------- 日志 "[_parent] field is disabled on indices with a single type." 的类名是 [ParentFieldMapper.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入背景的人参考: ```java } @Override public ParentFieldMapper build(BuilderContext context) { if (context.indexCreatedVersion().onOrAfter(Version.V_6_5_0)) { throw new MapperParsingException("[_parent] field is disabled on indices with a single type. " + "Use a [join] field instead."); } if (parentType == null) { throw new MapperParsingException("[_parent] field mapping must contain the [type] option"); } ```