--- title: "Boosting查询需要设置negative查询 - 如何解决此Elasticsearch异常" date: 2026-03-11 lastmod: 2026-03-11 description: "当Elasticsearch中的boosting查询缺少negative查询时会发生此错误。boosting查询需要同时设置positive和negative查询才能正常工作。" tags: ["Elasticsearch异常", "Boosting查询", "查询语法", "负查询"] summary: " 版本: 6.8-8.9 简而言之,当Elasticsearch中的’boosting’查询缺少’negative’查询时会出现此错误。‘boosting’查询需要同时设置’positive’和’negative’查询才能正常工作。要解决此问题,请确保在’boosting’查询中同时设置了’positive’和’negative’查询。如果你不想对任何文档产生负面影响,可以将’negative’查询设置为不匹配任何文档。或者,你可以使用’function_score’查询来实现更灵活的文档评分。 日志上下文 # 日志"[boosting] query requires ‘negative’ query to be set"的类名是 BoostingQueryBuilder.java。 我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入背景的人参考: if (positiveQueryFound == false) { throw new ParsingException(parser.getTokenLocation(); "[boosting] query requires 'positive' query to be set'"); } if (negativeQueryFound == false) { throw new ParsingException(parser.getTokenLocation(); "[boosting] query requires 'negative' query to be set'"); } if (negativeBoost < 0) { throw new ParsingException( parser.getTokenLocation(); "[boosting] query requires 'negative_boost' to be set to be a positive value'" " --- > **版本:** 6.8-8.9 简而言之,当Elasticsearch中的'boosting'查询缺少'negative'查询时会出现此错误。'boosting'查询需要同时设置'positive'和'negative'查询才能正常工作。要解决此问题,请确保在'boosting'查询中同时设置了'positive'和'negative'查询。如果你不想对任何文档产生负面影响,可以将'negative'查询设置为不匹配任何文档。或者,你可以使用'function_score'查询来实现更灵活的文档评分。 日志上下文 ----------- 日志"[boosting] query requires 'negative' query to be set"的类名是[BoostingQueryBuilder.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入背景的人参考: ```java if (positiveQueryFound == false) { throw new ParsingException(parser.getTokenLocation(); "[boosting] query requires 'positive' query to be set'"); } if (negativeQueryFound == false) { throw new ParsingException(parser.getTokenLocation(); "[boosting] query requires 'negative' query to be set'"); } if (negativeBoost < 0) { throw new ParsingException( parser.getTokenLocation(); "[boosting] query requires 'negative_boost' to be set to be a positive value'" ```