--- title: "聚合名称不支持正则表达式风格的include/exclude – 如何解决此Elasticsearch异常" date: 2026-02-10 lastmod: 2026-02-10 description: "当在不支持正则表达式的聚合中尝试使用正则表达式风格的include/exclude时,会出现此错误。解决方法包括移除正则表达式或切换到支持正则表达式的聚合类型。" tags: ["Elasticsearch异常", "聚合查询", "正则表达式", "RareTerms聚合"] summary: "版本: 6.8-7.7 简而言之,当您尝试在不支持正则表达式的聚合中使用正则表达式风格的include/exclude时,会出现此错误。并非所有Elasticsearch聚合都支持正则表达式。要解决此问题,您可以从聚合中移除正则表达式,或者切换到支持正则表达式的聚合类型,例如terms聚合。此外,请确保您的Elasticsearch版本支持聚合中的正则表达式,因为较早的版本可能不支持。 日志上下文 # 日志 “Aggregation [” + name + “] cannot support regular expression style include/exclude” 的类名是 RareTermsAggregatorFactory.java。我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: if ((includeExclude != null) && (includeExclude.isRegexBased())) { throw new AggregationExecutionException("Aggregation [" + name + "] cannot support regular expression style include/exclude " + "settings as they can only be applied to string fields. Use an array of numeric values for include/exclude clauses " + "used to filter numeric fields"); } if (valuesSource instanceof ValuesSource." --- > **版本:** 6.8-7.7 简而言之,当您尝试在不支持正则表达式的聚合中使用正则表达式风格的include/exclude时,会出现此错误。并非所有Elasticsearch聚合都支持正则表达式。要解决此问题,您可以从聚合中移除正则表达式,或者切换到支持正则表达式的聚合类型,例如terms聚合。此外,请确保您的Elasticsearch版本支持聚合中的正则表达式,因为较早的版本可能不支持。 ## 日志上下文 ----------- 日志 "Aggregation [" + name + "] cannot support regular expression style include/exclude" 的类名是 [RareTermsAggregatorFactory.java](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/)。我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: ```java if ((includeExclude != null) && (includeExclude.isRegexBased())) { throw new AggregationExecutionException("Aggregation [" + name + "] cannot support regular expression style include/exclude " + "settings as they can only be applied to string fields. Use an array of numeric values for include/exclude clauses " + "used to filter numeric fields"); } if (valuesSource instanceof ValuesSource.Numeric) { ```