--- title: "More Like This 查询解析失败:未指定 id 或 doc 参数 – 如何解决此 Elasticsearch 异常" date: 2026-01-22 lastmod: 2026-01-22 description: "当使用 Elasticsearch 的 More Like This (MLT) 查询时未指定 'id' 或 'doc' 参数,会导致解析失败异常。本文介绍该错误的产生原因及解决方法。" tags: ["Elasticsearch异常", "More Like This查询", "查询解析错误", "参数配置"] summary: "版本: 7.16-8.9 简而言之,当使用 Elasticsearch 的 More Like This (MLT) 查询时,如果没有指定 ‘id’ 或 ‘doc’ 参数,就会出现此错误。MLT 查询需要这两个参数中的任意一个来识别作为查找相似文档基础的文档。要解决此问题,您可以指定现有文档的 ‘id’,或者通过 ‘doc’ 参数提供文档内容。在使用 ‘id’ 时,请确保文档存在;对于 ‘doc’,请确保内容格式正确。 日志上下文 # 日志 “failed to parse More Like This item. neither [id] nor [doc] is specified!” 的类名是 MoreLikeThisQueryBuilder.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些需要深入理解上下文的人参考: throw new ElasticsearchParseException( "failed to parse More Like This item. either [id] or [doc] can be specified; but not both!" ); } if (item.id == null && item." --- > **版本:** 7.16-8.9 简而言之,当使用 Elasticsearch 的 More Like This (MLT) 查询时,如果没有指定 'id' 或 'doc' 参数,就会出现此错误。MLT 查询需要这两个参数中的任意一个来识别作为查找相似文档基础的文档。要解决此问题,您可以指定现有文档的 'id',或者通过 'doc' 参数提供文档内容。在使用 'id' 时,请确保文档存在;对于 'doc',请确保内容格式正确。 日志上下文 ----------- 日志 "failed to parse More Like This item. neither [id] nor [doc] is specified!" 的类名是 [MoreLikeThisQueryBuilder.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些需要深入理解上下文的人参考: ```java throw new ElasticsearchParseException( "failed to parse More Like This item. either [id] or [doc] can be specified; but not both!" ); } if (item.id == null && item.doc == null) { throw new ElasticsearchParseException("failed to parse More Like This item. neither [id] nor [doc] is specified!"); } return item; } @Override ```