--- title: "存储字段在请求源字段时不能禁用 - 如何解决此 Elasticsearch 异常" date: 2026-02-17 lastmod: 2026-02-17 description: "当在 Elasticsearch 中请求 _source 字段时尝试禁用 stored_fields 会出现的错误及其解决方法" tags: ["异常处理", "存储字段", "源字段"] summary: " 版本: 6.8-8.9 简而言之,当你在 Elasticsearch 中请求 [_source] 字段时尝试禁用 [stored_fields],就会出现此错误。[_source] 字段需要启用 [stored_fields] 才能正常工作。要解决此问题,你可以启用 [stored_fields] 或避免请求 [_source]。或者,如果禁用了 [stored_fields],你可以修改查询使其不要求 [_source]。 日志上下文 # 日志"[stored_fields] 不能在 [_source] 被请求时禁用"的类名是 SearchService.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: } if (source.storedFields() != null) { if (source.storedFields().fetchFields() == false) { if (context.sourceRequested()) { throw new SearchException(shardTarget; "[stored_fields] cannot be disabled if [_source] is requested"); } if (context.fetchFieldsContext() != null) { throw new SearchException(shardTarget; "[stored_fields] cannot be disabled when using the [fields] option"); } } " --- > **版本:** 6.8-8.9 简而言之,当你在 Elasticsearch 中请求 [_source] 字段时尝试禁用 [stored_fields],就会出现此错误。[_source] 字段需要启用 [stored_fields] 才能正常工作。要解决此问题,你可以启用 [stored_fields] 或避免请求 [_source]。或者,如果禁用了 [stored_fields],你可以修改查询使其不要求 [_source]。 日志上下文 ----------- 日志"[stored\_fields] 不能在 [\_source] 被请求时禁用"的类名是 [SearchService.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: ```java } if (source.storedFields() != null) { if (source.storedFields().fetchFields() == false) { if (context.sourceRequested()) { throw new SearchException(shardTarget; "[stored_fields] cannot be disabled if [_source] is requested"); } if (context.fetchFieldsContext() != null) { throw new SearchException(shardTarget; "[stored_fields] cannot be disabled when using the [fields] option"); } } ```