--- title: "请求版本时无法禁用存储字段 – 如何解决此Elasticsearch异常" date: 2026-02-11 lastmod: 2026-02-11 description: "在Elasticsearch中请求版本时尝试禁用stored_fields会导致异常。本文介绍了该错误的原因及解决方法。" tags: ["存储字段", "版本控制", "异常处理"] summary: " 版本: 6.8-7.9 简而言之,当你在Elasticsearch中请求版本的同时尝试禁用 stored_fields 时,就会发生此错误。Elasticsearch中的版本控制系统需要 stored_fields 来跟踪文档中的更改。要解决此问题,你可以启用 stored_fields 或者不请求版本。如果你不需要版本控制,只需移除版本请求即可。如果版本控制是必要的,请确保启用 stored_fields。 日志上下文 # 日志"stored\_fields cannot be disabled if version is requested"的类名是 SearchService.java。 我们从Elasticsearch源代码中提取了以下内容,为那些寻求深入背景的人提供参考: } if (source.storedFields() != null) { if (source.storedFields().fetchFields() == false) { if (context.version()) { throw new SearchException(shardTarget; "`stored_fields` cannot be disabled if version is requested"); } if (context.sourceRequested()) { throw new SearchException(shardTarget; "`stored_fields` cannot be disabled if _source is requested"); } } } " --- > **版本:** 6.8-7.9 简而言之,当你在Elasticsearch中请求版本的同时尝试禁用 `stored_fields` 时,就会发生此错误。Elasticsearch中的版本控制系统需要 `stored_fields` 来跟踪文档中的更改。要解决此问题,你可以启用 `stored_fields` 或者不请求版本。如果你不需要版本控制,只需移除版本请求即可。如果版本控制是必要的,请确保启用 `stored_fields`。 日志上下文 ----------- 日志"`stored\_fields` cannot be disabled if version is requested"的类名是[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.version()) { throw new SearchException(shardTarget; "`stored_fields` cannot be disabled if version is requested"); } if (context.sourceRequested()) { throw new SearchException(shardTarget; "`stored_fields` cannot be disabled if _source is requested"); } } } ```