|
@@ -150,14 +150,22 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ SubAggCollectionMode cm = collectMode;
|
|
|
+ if (cm == null) {
|
|
|
+ cm = SubAggCollectionMode.DEPTH_FIRST;
|
|
|
+ if (factories != AggregatorFactories.EMPTY) {
|
|
|
+ cm = subAggCollectionMode(bucketCountThresholds.getShardSize(), maxOrd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
DocValueFormat format = config.format();
|
|
|
if ((includeExclude != null) && (includeExclude.isRegexBased()) && format != DocValueFormat.RAW) {
|
|
|
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 values for include/exclude clauses");
|
|
|
}
|
|
|
|
|
|
- return execution.create(name, factories, valuesSource, order, format, bucketCountThresholds, includeExclude, context, parent,
|
|
|
- collectMode, showTermDocCountError, pipelineAggregators, metaData);
|
|
|
+ return execution.create(name, factories, valuesSource, order, format, bucketCountThresholds, includeExclude, context, parent,
|
|
|
+ cm, showTermDocCountError, pipelineAggregators, metaData);
|
|
|
}
|
|
|
|
|
|
if ((includeExclude != null) && (includeExclude.isRegexBased())) {
|
|
@@ -167,19 +175,27 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
|
|
|
|
|
|
if (valuesSource instanceof ValuesSource.Numeric) {
|
|
|
IncludeExclude.LongFilter longFilter = null;
|
|
|
+ SubAggCollectionMode cm = collectMode;
|
|
|
+ if (cm == null) {
|
|
|
+ if (factories != AggregatorFactories.EMPTY) {
|
|
|
+ cm = subAggCollectionMode(bucketCountThresholds.getShardSize(), -1);
|
|
|
+ } else {
|
|
|
+ cm = SubAggCollectionMode.DEPTH_FIRST;
|
|
|
+ }
|
|
|
+ }
|
|
|
if (((ValuesSource.Numeric) valuesSource).isFloatingPoint()) {
|
|
|
if (includeExclude != null) {
|
|
|
longFilter = includeExclude.convertToDoubleFilter();
|
|
|
}
|
|
|
return new DoubleTermsAggregator(name, factories, (ValuesSource.Numeric) valuesSource, config.format(), order,
|
|
|
- bucketCountThresholds, context, parent, collectMode, showTermDocCountError, longFilter,
|
|
|
+ bucketCountThresholds, context, parent, cm, showTermDocCountError, longFilter,
|
|
|
pipelineAggregators, metaData);
|
|
|
}
|
|
|
if (includeExclude != null) {
|
|
|
longFilter = includeExclude.convertToLongFilter(config.format());
|
|
|
}
|
|
|
return new LongTermsAggregator(name, factories, (ValuesSource.Numeric) valuesSource, config.format(), order,
|
|
|
- bucketCountThresholds, context, parent, collectMode, showTermDocCountError, longFilter, pipelineAggregators,
|
|
|
+ bucketCountThresholds, context, parent, cm, showTermDocCountError, longFilter, pipelineAggregators,
|
|
|
metaData);
|
|
|
}
|
|
|
|
|
@@ -187,6 +203,20 @@ public class TermsAggregatorFactory extends ValuesSourceAggregatorFactory<Values
|
|
|
+ "]. 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
|
|
|
+ static SubAggCollectionMode subAggCollectionMode(int expectedSize, long maxOrd) {
|
|
|
+ if (expectedSize == Integer.MAX_VALUE) {
|
|
|
+ // return all buckets
|
|
|
+ return SubAggCollectionMode.DEPTH_FIRST;
|
|
|
+ }
|
|
|
+ if (maxOrd == -1 || maxOrd > expectedSize) {
|
|
|
+ // use breadth_first if the cardinality is bigger than the expected size or unknown (-1)
|
|
|
+ return SubAggCollectionMode.BREADTH_FIRST;
|
|
|
+ }
|
|
|
+ return SubAggCollectionMode.DEPTH_FIRST;
|
|
|
+ }
|
|
|
+
|
|
|
public enum ExecutionMode {
|
|
|
|
|
|
MAP(new ParseField("map")) {
|