--- title: "Fetch fields 参数不能为空 - 如何解决此 Elasticsearch 异常" date: 2026-03-02 lastmod: 2026-03-02 description: "当 Elasticsearch 查询中的 fetch_fields 参数为空时会报此错误。该参数用于指定响应中应返回哪些字段。如果为空,Elasticsearch 不知道要获取哪些字段。" tags: ["查询参数", "字段获取", "参数验证"] summary: " 版本: 8.2-8.9 简而言之,当 Elasticsearch 查询中的 [fetch_fields] 参数为空时,就会发生此错误。该参数用于指定响应中应返回哪些字段。如果为空,Elasticsearch 不知道要获取哪些字段。要解决此问题,您可以在 [fetch_fields] 参数中指定要获取的字段,或者如果要返回所有字段,则完全删除该参数。 日志上下文 # 日志 “[fetch_fields] parameter must not be empty” 的类名是 LookupRuntimeFieldType.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: XContentBuilder::field; Object::toString ); fetchFields.addValidator(fields -> { if (fields.isEmpty()) { throw new MapperParsingException("[fetch_fields] parameter must not be empty"); } }); return fetchFields; } " --- > **版本:** 8.2-8.9 简而言之,当 Elasticsearch 查询中的 [fetch_fields] 参数为空时,就会发生此错误。该参数用于指定响应中应返回哪些字段。如果为空,Elasticsearch 不知道要获取哪些字段。要解决此问题,您可以在 [fetch_fields] 参数中指定要获取的字段,或者如果要返回所有字段,则完全删除该参数。 日志上下文 ----------- 日志 "[fetch\_fields] parameter must not be empty" 的类名是 [LookupRuntimeFieldType.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: ```java XContentBuilder::field; Object::toString ); fetchFields.addValidator(fields -> { if (fields.isEmpty()) { throw new MapperParsingException("[fetch_fields] parameter must not be empty"); } }); return fetchFields; } ```