--- title: "固定查询规则操作必须包含 ids 或 docs - 如何解决此 Elasticsearch 异常" date: 2026-01-03 lastmod: 2026-01-03 description: "Elasticsearch 固定查询规则操作必须包含 ids 或 docs 异常的解决方案" tags: ["固定查询", "查询规则", "异常处理"] summary: " 版本: 8.9-8.9 简要来说,当 Elasticsearch 中的固定查询(Pinned Query)未正确配置时,就会发生此错误。固定查询用于将选定的文档提升到搜索结果中更高的排名。它需要使用 ‘ids’ 或 ‘docs’ 来指定要提升哪些文档。如果两者都未提供,就会抛出此错误。要解决此问题,请确保您的固定查询包含 ‘ids’ 或 ‘docs’。如果您使用 ‘ids’,请提供要提升的文档的 ID。如果您使用 ‘docs’,请提供实际的文档。确保语法正确且指定的文档存在于您的索引中。 日志上下文 # 日志 “固定查询规则操作必须包含 ids 或 docs” 的类名是 QueryRule.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人使用: } private void validate() { if (type == QueryRuleType.PINNED) { if (actions.containsKey("ids") == false && actions.containsKey("docs") == false) { throw new ElasticsearchParseException("Pinned Query rule actions must contain either ids or docs"); } } else { throw new IllegalArgumentException("Unsupported QueryRuleType: " + type); } } " --- > **版本:** 8.9-8.9 简要来说,当 Elasticsearch 中的固定查询(Pinned Query)未正确配置时,就会发生此错误。固定查询用于将选定的文档提升到搜索结果中更高的排名。它需要使用 'ids' 或 'docs' 来指定要提升哪些文档。如果两者都未提供,就会抛出此错误。要解决此问题,请确保您的固定查询包含 'ids' 或 'docs'。如果您使用 'ids',请提供要提升的文档的 ID。如果您使用 'docs',请提供实际的文档。确保语法正确且指定的文档存在于您的索引中。 日志上下文 ----------- 日志 "固定查询规则操作必须包含 ids 或 docs" 的类名是 [QueryRule.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人使用: ```java } private void validate() { if (type == QueryRuleType.PINNED) { if (actions.containsKey("ids") == false && actions.containsKey("docs") == false) { throw new ElasticsearchParseException("Pinned Query rule actions must contain either ids or docs"); } } else { throw new IllegalArgumentException("Unsupported QueryRuleType: " + type); } } ```