--- title: "父字段映射必须包含 type 选项——如何解决此 Elasticsearch 异常" date: 2026-03-16 lastmod: 2026-03-16 description: "当 Elasticsearch 映射中的 [_parent] 字段缺少 [type] 选项时会出现此错误。本文介绍如何解决该异常。" tags: ["映射错误", "父字段", "类型选项", "异常处理"] summary: "版本: 6.8-6.8 简而言之,当 Elasticsearch 映射中的 [_parent] 字段缺少 [type] 选项时,会发生此错误。[type] 选项对于指定父文档类型是必需的。要解决此问题,您可以在映射的 [_parent] 字段中添加 [type] 选项。或者,如果您的用例不需要 [_parent] 字段,也可以将其删除。此外,重要的是要确保在 [_parent] 字段中引用父类型之前,该父类型已存在于您的索引中。 日志上下文 # 日志"[_parent] field mapping must contain the [type] option"的类名是 ParentFieldMapper.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入背景信息的人参考: 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"); } name = joinField(parentType); setupFieldType(context); return new ParentFieldMapper(createParentJoinFieldMapper(documentType; context); fieldType; parentType; context." --- > **版本:** 6.8-6.8 简而言之,当 Elasticsearch 映射中的 [_parent] 字段缺少 [type] 选项时,会发生此错误。[type] 选项对于指定父文档类型是必需的。要解决此问题,您可以在映射的 [_parent] 字段中添加 [type] 选项。或者,如果您的用例不需要 [_parent] 字段,也可以将其删除。此外,重要的是要确保在 [_parent] 字段中引用父类型之前,该父类型已存在于您的索引中。 日志上下文 ----------- 日志"[_parent] field mapping must contain the [type] option"的类名是 [ParentFieldMapper.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入背景信息的人参考: ```java 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"); } name = joinField(parentType); setupFieldType(context); return new ParentFieldMapper(createParentJoinFieldMapper(documentType; context); fieldType; parentType; context.indexSettings()); ```