Java Code Examples for org.elasticsearch.search.aggregations.support.ValuesSource#Numeric

The following examples show how to use org.elasticsearch.search.aggregations.support.ValuesSource#Numeric . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateHierarchyAggregatorFactory.java    From elasticsearch-aggregation-pathhierarchy with MIT License 6 votes vote down vote up
DateHierarchyAggregatorFactory(String name,
                               ValuesSourceConfig<ValuesSource.Numeric> config,
                               BucketOrder order,
                               List<DateHierarchyAggregationBuilder.RoundingInfo> roundingsInfo,
                               long minDocCount,
                               DateHierarchyAggregator.BucketCountThresholds bucketCountThresholds,
                               QueryShardContext context,
                               AggregatorFactory parent,
                               AggregatorFactories.Builder subFactoriesBuilder,
                               Map<String, Object> metaData
) throws IOException {
    super(name, config, context, parent, subFactoriesBuilder, metaData);
    this.order = order;
    this.roundingsInfo = roundingsInfo;
    this.minDocCount = minDocCount;
    this.bucketCountThresholds = bucketCountThresholds;
}
 
Example 2
Source File: HistogramAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public HistogramAggregator(String name, AggregatorFactories factories, Rounding rounding, InternalOrder order, boolean keyed,
        long minDocCount, @Nullable ExtendedBounds extendedBounds, @Nullable ValuesSource.Numeric valuesSource,
        ValueFormatter formatter, InternalHistogram.Factory<?> histogramFactory, AggregationContext aggregationContext,
        Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {

    super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
    this.rounding = rounding;
    this.order = order;
    this.keyed = keyed;
    this.minDocCount = minDocCount;
    this.extendedBounds = extendedBounds;
    this.valuesSource = valuesSource;
    this.formatter = formatter;
    this.histogramFactory = histogramFactory;

    bucketOrds = new LongHash(1, aggregationContext.bigArrays());
}
 
Example 3
Source File: DateHierarchyAggregatorFactory.java    From elasticsearch-aggregation-pathhierarchy with MIT License 6 votes vote down vote up
@Override
protected Aggregator doCreateInternal(
        ValuesSource.Numeric valuesSource, SearchContext searchContext, Aggregator parent,
        boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators,
        Map<String, Object> metaData) throws IOException {

    DateHierarchyAggregator.BucketCountThresholds bucketCountThresholds = new
            DateHierarchyAggregator.BucketCountThresholds(this.bucketCountThresholds);
    if (!InternalOrder.isKeyOrder(order)
            && bucketCountThresholds.getShardSize() == DateHierarchyAggregationBuilder.DEFAULT_BUCKET_COUNT_THRESHOLDS.getShardSize()) {
        // The user has not made a shardSize selection. Use default
        // heuristic to avoid any wrong-ranking caused by distributed
        // counting
        bucketCountThresholds.setShardSize(BucketUtils.suggestShardSideQueueSize(bucketCountThresholds.getRequiredSize()));
    }
    bucketCountThresholds.ensureValidity();
    return new DateHierarchyAggregator(
            name, factories, searchContext,
            valuesSource, order, minDocCount, bucketCountThresholds, roundingsInfo,
            parent, pipelineAggregators, metaData);
}
 
Example 4
Source File: HistogramAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected Aggregator doCreateInternal(ValuesSource.Numeric valuesSource, AggregationContext aggregationContext, Aggregator parent,
        boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
    if (collectsFromSingleBucket == false) {
        return asMultiBucketAggregator(this, aggregationContext, parent);
    }
    // we need to round the bounds given by the user and we have to do it for every aggregator we crate
    // as the rounding is not necessarily an idempotent operation.
    // todo we need to think of a better structure to the factory/agtor code so we won't need to do that
    ExtendedBounds roundedBounds = null;
    if (extendedBounds != null) {
        // we need to process & validate here using the parser
        extendedBounds.processAndValidate(name, aggregationContext.searchContext(), config.parser());
        roundedBounds = extendedBounds.round(rounding);
    }
    return new HistogramAggregator(name, factories, rounding, order, keyed, minDocCount, roundedBounds, valuesSource,
            config.formatter(), histogramFactory, aggregationContext, parent, pipelineAggregators, metaData);
}
 
Example 5
Source File: StatsAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public StatsAggregator(String name, ValuesSource.Numeric valuesSource, ValueFormatter formatter,
                       AggregationContext context,
                       Aggregator parent, List<PipelineAggregator> pipelineAggregators,
                       Map<String, Object> metaData) throws IOException {
    super(name, context, parent, pipelineAggregators, metaData);
    this.valuesSource = valuesSource;
    if (valuesSource != null) {
        final BigArrays bigArrays = context.bigArrays();
        counts = bigArrays.newLongArray(1, true);
        sums = bigArrays.newDoubleArray(1, true);
        mins = bigArrays.newDoubleArray(1, false);
        mins.fill(0, mins.size(), Double.POSITIVE_INFINITY);
        maxes = bigArrays.newDoubleArray(1, false);
        maxes.fill(0, maxes.size(), Double.NEGATIVE_INFINITY);
    }
    this.formatter = formatter;
}
 
Example 6
Source File: RangeAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public RangeAggregator(String name, AggregatorFactories factories, ValuesSource.Numeric valuesSource, ValueFormat format,
        InternalRange.Factory rangeFactory, List<Range> ranges, boolean keyed, AggregationContext aggregationContext,
        Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {

    super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
    assert valuesSource != null;
    this.valuesSource = valuesSource;
    this.formatter = format.formatter();
    this.keyed = keyed;
    this.rangeFactory = rangeFactory;
    this.ranges = ranges.toArray(new Range[ranges.size()]);

    ValueParser parser = format != null ? format.parser() : ValueParser.RAW;
    for (int i = 0; i < this.ranges.length; i++) {
        this.ranges[i].process(parser, context.searchContext());
    }
    sortRanges(this.ranges);

    maxTo = new double[this.ranges.length];
    maxTo[0] = this.ranges[0].to;
    for (int i = 1; i < this.ranges.length; ++i) {
        maxTo[i] = Math.max(this.ranges[i].to,maxTo[i-1]);
    }

}
 
Example 7
Source File: DateHierarchyAggregator.java    From elasticsearch-aggregation-pathhierarchy with MIT License 6 votes vote down vote up
public DateHierarchyAggregator(
        String name,
        AggregatorFactories factories,
        SearchContext context,
        ValuesSource.Numeric valuesSource,
        BucketOrder order,
        long minDocCount,
        BucketCountThresholds bucketCountThresholds,
        List<DateHierarchyAggregationBuilder.RoundingInfo> roundingsInfo,
        Aggregator parent,
        List<PipelineAggregator> pipelineAggregators,
        Map<String, Object> metaData
) throws IOException {
    super(name, factories, context, parent, pipelineAggregators, metaData);
    this.valuesSource = valuesSource;
    this.roundingsInfo = roundingsInfo;
    this.minDocCount = minDocCount;
    bucketOrds =  new BytesRefHash(1, context.bigArrays());
    this.order = InternalOrder.validate(order, this);
    this.bucketCountThresholds = bucketCountThresholds;
}
 
Example 8
Source File: TDigestPercentileRanksAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected Aggregator doCreateInternal(ValuesSource.Numeric valuesSource, AggregationContext aggregationContext, Aggregator parent,
        boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
        throws IOException {
    return new TDigestPercentileRanksAggregator(name, valuesSource, aggregationContext, parent, values, compression, keyed,
            config.formatter(), pipelineAggregators, metaData);
}
 
Example 9
Source File: DoubleTermsAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public DoubleTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Numeric valuesSource, ValueFormat format,
        Terms.Order order, BucketCountThresholds bucketCountThresholds, AggregationContext aggregationContext, Aggregator parent,
        SubAggCollectionMode collectionMode, boolean showTermDocCountError, IncludeExclude.LongFilter longFilter,
        List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
    super(name, factories, valuesSource, format, order, bucketCountThresholds, aggregationContext, parent, collectionMode,
            showTermDocCountError, longFilter, pipelineAggregators, metaData);
}
 
Example 10
Source File: ExtendedStatsAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected Aggregator doCreateInternal(ValuesSource.Numeric valuesSource, AggregationContext aggregationContext, Aggregator parent,
        boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
        throws IOException {
    return new ExtendedStatsAggregator(name, valuesSource, config.formatter(), aggregationContext, parent, sigma,
            pipelineAggregators, metaData);
}
 
Example 11
Source File: ExtendedStatsParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser<ValuesSource.Numeric> vsParser = ValuesSourceParser.numeric(aggregationName, InternalExtendedStats.TYPE, context).formattable(true)
            .build();

    XContentParser.Token token;
    String currentFieldName = null;
    double sigma = 2.0;

    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else if (token == XContentParser.Token.VALUE_NUMBER) {
            if (context.parseFieldMatcher().match(currentFieldName, SIGMA)) {
                sigma = parser.doubleValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    if (sigma < 0) {
        throw new SearchParseException(context, "[sigma] must not be negative. Value provided was" + sigma, parser.getTokenLocation());
    }

    return createFactory(aggregationName, vsParser.config(), sigma);
}
 
Example 12
Source File: SumAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public SumAggregator(String name, ValuesSource.Numeric valuesSource, ValueFormatter formatter, AggregationContext context,
        Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
    super(name, context, parent, pipelineAggregators, metaData);
    this.valuesSource = valuesSource;
    this.formatter = formatter;
    if (valuesSource != null) {
        sums = context.bigArrays().newDoubleArray(1, true);
    }
}
 
Example 13
Source File: SamplerAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@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.");
}
 
Example 14
Source File: MinAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public MinAggregator(String name, ValuesSource.Numeric valuesSource, ValueFormatter formatter,
        AggregationContext context, Aggregator parent, List<PipelineAggregator> pipelineAggregators,
        Map<String, Object> metaData) throws IOException {
    super(name, context, parent, pipelineAggregators, metaData);
    this.valuesSource = valuesSource;
    if (valuesSource != null) {
        mins = context.bigArrays().newDoubleArray(1, false);
        mins.fill(0, mins.size(), Double.POSITIVE_INFINITY);
    }
    this.formatter = formatter;
}
 
Example 15
Source File: AbstractHDRPercentilesAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public AbstractHDRPercentilesAggregator(String name, ValuesSource.Numeric valuesSource, AggregationContext context, Aggregator parent,
        double[] keys, int numberOfSignificantValueDigits, boolean keyed, ValueFormatter formatter,
        List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
    super(name, context, parent, pipelineAggregators, metaData);
    this.valuesSource = valuesSource;
    this.keyed = keyed;
    this.formatter = formatter;
    this.states = context.bigArrays().newObjectArray(1);
    this.keys = keys;
    this.numberOfSignificantValueDigits = numberOfSignificantValueDigits;
}
 
Example 16
Source File: DateHierarchyAggregationBuilder.java    From elasticsearch-aggregation-pathhierarchy with MIT License 5 votes vote down vote up
@Override
protected ValuesSourceAggregatorFactory<ValuesSource.Numeric> innerBuild(
        QueryShardContext context,
        ValuesSourceConfig<ValuesSource.Numeric> config,
        AggregatorFactory parent,
        Builder subFactoriesBuilder) throws IOException {

    final List<RoundingInfo> roundingsInfo = buildRoundings();

    return new DateHierarchyAggregatorFactory(
            name, config, order, roundingsInfo, minDocCount, bucketCountThresholds,
            context, parent, subFactoriesBuilder, metaData);
}
 
Example 17
Source File: MaxAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Factory(String name, ValuesSourceConfig<ValuesSource.Numeric> valuesSourceConfig) {
    super(name, InternalMax.TYPE.name(), valuesSourceConfig);
}
 
Example 18
Source File: MinAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected Aggregator doCreateInternal(ValuesSource.Numeric valuesSource, AggregationContext aggregationContext, Aggregator parent,
        boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
        throws IOException {
    return new MinAggregator(name, valuesSource, config.formatter(), aggregationContext, parent, pipelineAggregators, metaData);
}
 
Example 19
Source File: MaxAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected Aggregator doCreateInternal(ValuesSource.Numeric valuesSource, AggregationContext aggregationContext, Aggregator parent,
        boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
        throws IOException {
    return new MaxAggregator(name, valuesSource, config.formatter(), aggregationContext, parent, pipelineAggregators, metaData);
}
 
Example 20
Source File: NumericValuesSourceMetricsAggregatorParser.java    From Elasticsearch with Apache License 2.0 votes vote down vote up
protected abstract AggregatorFactory createFactory(String aggregationName, ValuesSourceConfig<ValuesSource.Numeric> config);