RareTerms aggregation cannot be applied to field – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 7.3-7.7

Briefly, this error occurs when the RareTerms aggregation is applied to a field that is not suitable for this type of operation. This could be due to the field being non-keyword or non-numeric. To resolve this issue, you can either change the field type to keyword or numeric, or use a different aggregation that is compatible with the current field type. Another solution could be to create a new keyword or numeric field from the existing one and apply the RareTerms aggregation to this new field.

This guide will help you check for common problems that cause the log ” RareTerms aggregation cannot be applied to field [ ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: search, aggregations.

Log Context

Log “RareTerms aggregation cannot be applied to field [” class name is RareTermsAggregatorFactory.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 return new LongRareTermsAggregator(name; factories; (ValuesSource.Numeric) valuesSource; config.format();
 searchContext; parent; longFilter; maxDocCount; precision; pipelineAggregators; metaData);
 }  throw new AggregationExecutionException("RareTerms aggregation cannot be applied to field [" + config.fieldContext().field()
 + "]. It can only be applied to numeric or string fields.");
 }  public enum ExecutionMode {


How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?