版本: 6.8-7.7
简而言之,当您尝试在非 keyword 类型的字段或未启用字段数据的字段上应用 terms 聚合时,会出现此错误。Elasticsearch 无法直接在 text 字段上执行 terms 聚合。要解决此问题,您可以将字段类型更改为 keyword 或启用字段数据。或者,如果所讨论的 text 字段存在 keyword 子字段,您可以使用它。最后,您可以使用脚本在执行聚合之前将字段转换为字符串。
日志上下文 #
日志 “terms aggregation cannot be applied to field [” 的类名是 TermsAggregatorFactory.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入背景信息的人参考:
return new LongTermsAggregator(name; factories; (ValuesSource.Numeric) valuesSource; config.format(); order;
bucketCountThresholds; searchContext; parent; cm; showTermDocCountError; longFilter; pipelineAggregators;
metaData);
} throw new AggregationExecutionException("terms aggregation cannot be applied to field [" + config.fieldContext().field()
+ "]. It can only be applied to numeric or string fields.");
} // return the SubAggCollectionMode that this aggregation should use based on the expected size
// and the cardinality of the field





