--- title: "Span not 必须包含 exclude span query 子句 - 如何解决此 Elasticsearch 异常" date: 2026-03-26 lastmod: 2026-03-26 description: "Elasticsearch span_not 查询缺少必需的 exclude 子句时会导致此异常。本文介绍了错误原因及解决方法。" tags: ["Span查询", "查询异常", "Elasticsearch错误"] summary: "版本: 6.8-8.9 简要来说,当 Elasticsearch span_not 查询缺少必需的 [exclude] 子句时,就会出现此错误。span_not 查询用于匹配不在起始和结束 span 之间的 span,它需要同时包含 [include] 和 [exclude] 子句。要解决此问题,你应该检查查询,确保它同时包含 [include] 和 [exclude] 子句。如果缺少其中任何一个,请将其添加到查询中,然后重试。这应该能解决错误,使你的查询能够成功执行。 日志上下文 # 日志 “span_not must have [exclude] span query clause” 的类名是 SpanNotQueryBuilder.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: } if (include == null) { throw new ParsingException(parser.getTokenLocation(); "span_not must have [include] span query clause"); } if (exclude == null) { throw new ParsingException(parser.getTokenLocation(); "span_not must have [exclude] span query clause"); } if (dist !" --- > **版本:** 6.8-8.9 简要来说,当 Elasticsearch span_not 查询缺少必需的 [exclude] 子句时,就会出现此错误。span_not 查询用于匹配不在起始和结束 span 之间的 span,它需要同时包含 [include] 和 [exclude] 子句。要解决此问题,你应该检查查询,确保它同时包含 [include] 和 [exclude] 子句。如果缺少其中任何一个,请将其添加到查询中,然后重试。这应该能解决错误,使你的查询能够成功执行。 日志上下文 ----------- 日志 "span\_not must have [exclude] span query clause" 的类名是 [SpanNotQueryBuilder.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人参考: ```java } if (include == null) { throw new ParsingException(parser.getTokenLocation(); "span_not must have [include] span query clause"); } if (exclude == null) { throw new ParsingException(parser.getTokenLocation(); "span_not must have [exclude] span query clause"); } if (dist != null && (pre != null || post != null)) { throw new ParsingException(parser.getTokenLocation(); "span_not can either use [dist] or [pre] & [post] (or none)"); } ```