--- title: "Percolate 查询无法执行时 - 如何解决此 Elasticsearch 异常" date: 2026-01-07 lastmod: 2026-01-07 description: "当 Elasticsearch 索引没有映射类型时尝试执行 percolate 查询会导致此错误。本文介绍了解决方案,包括创建映射类型或使用其他查询方式。" tags: ["Percolate查询", "映射类型", "查询异常", "索引配置"] summary: " 版本: 7.7-7.15 简要来说,当在没有映射类型的 Elasticsearch 索引上尝试执行 percolate 查询时,会发生此错误。Percolate 查询用于测试文档是否匹配查询的条件。要解决此问题,您可以为索引创建映射类型,或者使用已经具有映射类型的其他索引。另外,如果您只是想从索引中检索所有文档,可以使用 match_all 查询代替 percolate 查询。 日志上下文 # 日志 “[percolate] queries cannot be executed when ‘” 的类名是 PercolateQueryBuilder.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: } @Override protected Query doToQuery(SearchExecutionContext context) throws IOException { if (context.allowExpensiveQueries() == false) { throw new ElasticsearchException("[percolate] queries cannot be executed when '" + ALLOW_EXPENSIVE_QUERIES.getKey() + "' is set to false."); } // Call nowInMillis() so that this query becomes un-cacheable since we // can't be sure that it doesn't use now or scripts " --- > **版本:** 7.7-7.15 简要来说,当在没有映射类型的 Elasticsearch 索引上尝试执行 percolate 查询时,会发生此错误。Percolate 查询用于测试文档是否匹配查询的条件。要解决此问题,您可以为索引创建映射类型,或者使用已经具有映射类型的其他索引。另外,如果您只是想从索引中检索所有文档,可以使用 match_all 查询代替 percolate 查询。 日志上下文 ----------- 日志 "[percolate] queries cannot be executed when '" 的类名是 [PercolateQueryBuilder.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: ```java } @Override protected Query doToQuery(SearchExecutionContext context) throws IOException { if (context.allowExpensiveQueries() == false) { throw new ElasticsearchException("[percolate] queries cannot be executed when '" + ALLOW_EXPENSIVE_QUERIES.getKey() + "' is set to false."); } // Call nowInMillis() so that this query becomes un-cacheable since we // can't be sure that it doesn't use now or scripts ```