--- title: "预期字段 – 如何解决此 Elasticsearch 异常" date: 2026-02-14 lastmod: 2026-02-14 description: "当 Elasticsearch 期望请求体中包含某个字段但未提供时出现的错误。通常由于字段名拼写错误或字段完全缺失导致。" tags: ["字段类型", "查询异常", "Percolate查询"] summary: "版本: 6.8-7.15 简而言之,当 Elasticsearch 期望请求体中包含某个字段,但该字段未提供时,就会发生此错误。这可能是由于字段名拼写错误或请求中完全缺少该字段造成的。要解决此问题,请确保请求中的字段名与 Elasticsearch 期望的字段名完全匹配。同时,检查请求中是否缺少该字段。如果该字段是可选的且您不想提供它,请确保不包含该字段的请求格式正确。 日志上下文 # 日志 “expected field [” 的类名是 PercolateQueryBuilder.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入理解的人参考: if (fieldType == null) { throw new QueryShardException(context, "field [" + field + "] does not exist"); } if ((fieldType instanceof PercolatorFieldMapper.PercolatorFieldType) == false) { throw new QueryShardException(context, "expected field [" + field + "] to be of type [percolator]; but is of type [" + fieldType.typeName() + "]"); } final List<ParsedDocument> docs = new ArrayList<>(); String type = context." --- > **版本:** 6.8-7.15 简而言之,当 Elasticsearch 期望请求体中包含某个字段,但该字段未提供时,就会发生此错误。这可能是由于字段名拼写错误或请求中完全缺少该字段造成的。要解决此问题,请确保请求中的字段名与 Elasticsearch 期望的字段名完全匹配。同时,检查请求中是否缺少该字段。如果该字段是可选的且您不想提供它,请确保不包含该字段的请求格式正确。 日志上下文 ----------- 日志 "expected field [" 的类名是 [PercolateQueryBuilder.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入理解的人参考: ```java if (fieldType == null) { throw new QueryShardException(context, "field [" + field + "] does not exist"); } if ((fieldType instanceof PercolatorFieldMapper.PercolatorFieldType) == false) { throw new QueryShardException(context, "expected field [" + field + "] to be of type [percolator]; but is of type [" + fieldType.typeName() + "]"); } final List docs = new ArrayList<>(); String type = context.getType(); ```