Search in sources :

Example 1 with InternalMin

use of org.elasticsearch.search.aggregations.metrics.min.InternalMin in project elasticsearch by elastic.

the class InternalSingleBucketAggregationTestCase method createTestInstance.

@Override
protected final T createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
    List<InternalAggregation> internal = new ArrayList<>();
    if (hasInternalMax) {
        internal.add(new InternalMax("max", randomDouble(), randomFrom(DocValueFormat.BOOLEAN, DocValueFormat.GEOHASH, DocValueFormat.IP, DocValueFormat.RAW), emptyList(), emptyMap()));
    }
    if (hasInternalMin) {
        internal.add(new InternalMin("min", randomDouble(), randomFrom(DocValueFormat.BOOLEAN, DocValueFormat.GEOHASH, DocValueFormat.IP, DocValueFormat.RAW), emptyList(), emptyMap()));
    }
    // we shouldn't use the full long range here since we sum doc count on reduce, and don't want to overflow the long range there
    long docCount = between(0, Integer.MAX_VALUE);
    return createTestInstance(name, docCount, new InternalAggregations(internal), pipelineAggregators, metaData);
}
Also used : InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) InternalAggregations(org.elasticsearch.search.aggregations.InternalAggregations) InternalMax(org.elasticsearch.search.aggregations.metrics.max.InternalMax) InternalMin(org.elasticsearch.search.aggregations.metrics.min.InternalMin) ArrayList(java.util.ArrayList)

Example 2 with InternalMin

use of org.elasticsearch.search.aggregations.metrics.min.InternalMin in project elasticsearch by elastic.

the class InternalSingleBucketAggregationTestCase method assertReduced.

@Override
protected final void assertReduced(T reduced, List<T> inputs) {
    assertEquals(inputs.stream().mapToLong(InternalSingleBucketAggregation::getDocCount).sum(), reduced.getDocCount());
    if (hasInternalMax) {
        double expected = inputs.stream().mapToDouble(i -> {
            InternalMax max = i.getAggregations().get("max");
            return max.getValue();
        }).max().getAsDouble();
        InternalMax reducedMax = reduced.getAggregations().get("max");
        assertEquals(expected, reducedMax.getValue(), 0);
    }
    if (hasInternalMin) {
        double expected = inputs.stream().mapToDouble(i -> {
            InternalMin min = i.getAggregations().get("min");
            return min.getValue();
        }).min().getAsDouble();
        InternalMin reducedMin = reduced.getAggregations().get("min");
        assertEquals(expected, reducedMin.getValue(), 0);
    }
    extraAssertReduced(reduced, inputs);
}
Also used : InternalMax(org.elasticsearch.search.aggregations.metrics.max.InternalMax) InternalMin(org.elasticsearch.search.aggregations.metrics.min.InternalMin)

Aggregations

InternalMax (org.elasticsearch.search.aggregations.metrics.max.InternalMax)2 InternalMin (org.elasticsearch.search.aggregations.metrics.min.InternalMin)2 ArrayList (java.util.ArrayList)1 InternalAggregation (org.elasticsearch.search.aggregations.InternalAggregation)1 InternalAggregations (org.elasticsearch.search.aggregations.InternalAggregations)1