--- title: "More like this 查询要求 fields 不能为空——如何解决此 Elasticsearch 异常" date: 2026-02-12 lastmod: 2026-02-12 description: "当 Elasticsearch 中的 more_like_this 查询的 'fields' 参数为空或未指定时,会出现此错误。本文介绍如何解决此异常。" tags: ["More Like This查询", "字段参数", "查询异常", "Elasticsearch错误"] summary: "版本: 6.8-8.9 简而言之,当 Elasticsearch 中 ‘more_like_this’ 查询的 ‘fields’ 参数为空或未指定时,会出现此错误。‘more_like_this’ 查询用于查找与给定文档集"相似"的文档。要解决此问题,请确保提供了 ‘fields’ 参数,并且至少包含一个字段名称。如果不确定使用哪些字段,可以考虑使用 ‘_all’ 来搜索所有字段。或者,你可以设置 ‘like’ 参数来指定要查找相似文档的文本。 日志上下文 # 日志 “more_like_this requires ‘fields’ to be non-empty” 的类名是 MoreLikeThisQueryBuilder.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人使用: if (likeTexts.isEmpty() && likeItems.isEmpty()) { throw new ParsingException(parser.getTokenLocation(); "more_like_this requires 'like' to be specified"); } if (fields != null && fields.isEmpty()) { throw new ParsingException(parser.getTokenLocation(); "more_like_this requires 'fields' to be non-empty"); } String[] fieldsArray = fields == null ?" --- > **版本:** 6.8-8.9 简而言之,当 Elasticsearch 中 'more_like_this' 查询的 'fields' 参数为空或未指定时,会出现此错误。'more_like_this' 查询用于查找与给定文档集"相似"的文档。要解决此问题,请确保提供了 'fields' 参数,并且至少包含一个字段名称。如果不确定使用哪些字段,可以考虑使用 '_all' 来搜索所有字段。或者,你可以设置 'like' 参数来指定要查找相似文档的文本。 日志上下文 ----------- 日志 "more\_like\_this requires 'fields' to be non-empty" 的类名是 [MoreLikeThisQueryBuilder.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人使用: ```java if (likeTexts.isEmpty() && likeItems.isEmpty()) { throw new ParsingException(parser.getTokenLocation(); "more_like_this requires 'like' to be specified"); } if (fields != null && fields.isEmpty()) { throw new ParsingException(parser.getTokenLocation(); "more_like_this requires 'fields' to be non-empty"); } String[] fieldsArray = fields == null ? null : fields.toArray(new String[fields.size()]); String[] likeTextsArray = likeTexts.isEmpty() ? null : likeTexts.toArray(new String[likeTexts.size()]); String[] unlikeTextsArray = unlikeTexts.isEmpty() ? null : unlikeTexts.toArray(new String[unlikeTexts.size()]); ```