--- title: "无法获取设置了 includes/excludes 的类型 type 和 id id - 如何解决此 Elasticsearch 异常" date: 2026-03-25 lastmod: 2026-03-25 description: "Elasticsearch 在获取设置了 includes/excludes 参数的特定类型和 id 文档时失败,通常是由于类型或 id 不正确,或 includes/excludes 参数设置不当导致的异常。" tags: ["文档获取", "includes/excludes", "字段过滤", "源文档", "ShardGetService"] summary: "简要来说,当 Elasticsearch 无法获取设置了 includes/excludes 参数的特定类型和 id 的文档时,会出现此错误。这可能是由于类型或 id 不正确,或者 includes/excludes 参数设置不当。要解决此问题,请确保类型和 id 正确且存在于数据库中。同时,检查 includes/excludes 参数的语法和用法。它们应该被正确使用来过滤返回的源文档字段。 版本: 6.8-7.17 日志上下文 # 日志 “Failed to get type [” + type + “] and id [” + id + “] with includes/excludes set” 的类名是 ShardGetService.java. 我们从 Elasticsearch 源代码中提取了以下内容,为那些寻求深入理解上下文的人提供参考: sourceAsMap = typeMapTuple.v2(); sourceAsMap = XContentMapValues.filter(sourceAsMap; fetchSourceContext.includes(); fetchSourceContext.excludes()); try { source = BytesReference.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); } catch (IOException e) { throw new ElasticsearchException("Failed to get type [" + type + "] and id [" + id + "] with includes/excludes set"; e); } } return new GetResult( shardId." --- 简要来说,当 Elasticsearch 无法获取设置了 includes/excludes 参数的特定类型和 id 的文档时,会出现此错误。这可能是由于类型或 id 不正确,或者 includes/excludes 参数设置不当。要解决此问题,请确保类型和 id 正确且存在于数据库中。同时,检查 includes/excludes 参数的语法和用法。它们应该被正确使用来过滤返回的源文档字段。 > **版本:** 6.8-7.17 日志上下文 ----------- 日志 "Failed to get type [" + type + "] and id [" + id + "] with includes/excludes set" 的类名是 [ShardGetService.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,为那些寻求深入理解上下文的人提供参考: ```java sourceAsMap = typeMapTuple.v2(); sourceAsMap = XContentMapValues.filter(sourceAsMap; fetchSourceContext.includes(); fetchSourceContext.excludes()); try { source = BytesReference.bytes(XContentFactory.contentBuilder(sourceContentType).map(sourceAsMap)); } catch (IOException e) { throw new ElasticsearchException("Failed to get type [" + type + "] and id [" + id + "] with includes/excludes set"; e); } } return new GetResult( shardId.getIndexName(); ```