Search in sources :

Example 1 with InvalidAggregationPathException

use of org.elasticsearch.search.aggregations.InvalidAggregationPathException in project elasticsearch by elastic.

the class BucketHelpers method resolveBucketValue.

public static Double resolveBucketValue(MultiBucketsAggregation agg, InternalMultiBucketAggregation.Bucket bucket, List<String> aggPathAsList, GapPolicy gapPolicy) {
    try {
        Object propertyValue = bucket.getProperty(agg.getName(), aggPathAsList);
        if (propertyValue == null) {
            throw new AggregationExecutionException(AbstractPipelineAggregationBuilder.BUCKETS_PATH_FIELD.getPreferredName() + " must reference either a number value or a single value numeric metric aggregation");
        } else {
            double value;
            if (propertyValue instanceof Number) {
                value = ((Number) propertyValue).doubleValue();
            } else if (propertyValue instanceof InternalNumericMetricsAggregation.SingleValue) {
                value = ((InternalNumericMetricsAggregation.SingleValue) propertyValue).value();
            } else {
                throw new AggregationExecutionException(AbstractPipelineAggregationBuilder.BUCKETS_PATH_FIELD.getPreferredName() + " must reference either a number value or a single value numeric metric aggregation, got: " + propertyValue.getClass().getCanonicalName());
            }
            // doc count never has missing values so gap policy doesn't apply here
            boolean isDocCountProperty = aggPathAsList.size() == 1 && "_count".equals(aggPathAsList.get(0));
            if (Double.isInfinite(value) || Double.isNaN(value) || (bucket.getDocCount() == 0 && !isDocCountProperty)) {
                switch(gapPolicy) {
                    case INSERT_ZEROS:
                        return 0.0;
                    case SKIP:
                    default:
                        return Double.NaN;
                }
            } else {
                return value;
            }
        }
    } catch (InvalidAggregationPathException e) {
        return null;
    }
}
Also used : InternalNumericMetricsAggregation(org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation) InvalidAggregationPathException(org.elasticsearch.search.aggregations.InvalidAggregationPathException) AggregationExecutionException(org.elasticsearch.search.aggregations.AggregationExecutionException)

Aggregations

AggregationExecutionException (org.elasticsearch.search.aggregations.AggregationExecutionException)1 InvalidAggregationPathException (org.elasticsearch.search.aggregations.InvalidAggregationPathException)1 InternalNumericMetricsAggregation (org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation)1