@Override protected Aggregator doCreateInternal( ValuesSource valuesSource, AggregationContext context, Aggregator parent, boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { if (valuesSource instanceof ValuesSource.Numeric) { return new DiversifiedNumericSamplerAggregator( name, shardSize, factories, context, parent, pipelineAggregators, metaData, (Numeric) valuesSource, maxDocsPerValue); } if (valuesSource instanceof ValuesSource.Bytes) { ExecutionMode execution = null; if (executionHint != null) { execution = ExecutionMode.fromString(executionHint, context.searchContext().parseFieldMatcher()); } // In some cases using ordinals is just not supported: override // it if (execution == null) { execution = ExecutionMode.GLOBAL_ORDINALS; } if ((execution.needsGlobalOrdinals()) && (!(valuesSource instanceof ValuesSource.Bytes.WithOrdinals))) { execution = ExecutionMode.MAP; } return execution.create( name, factories, shardSize, maxDocsPerValue, valuesSource, context, parent, pipelineAggregators, metaData); } throw new AggregationExecutionException( "Sampler aggregation cannot be applied to field [" + config.fieldContext().field() + "]. It can only be applied to numeric or string fields."); }