Search in sources :

Example 1 with Rounding

use of org.elasticsearch.common.rounding.Rounding in project elasticsearch by elastic.

the class DateHistogramAggregationBuilder method innerBuild.

@Override
protected ValuesSourceAggregatorFactory<Numeric, ?> innerBuild(SearchContext context, ValuesSourceConfig<Numeric> config, AggregatorFactory<?> parent, Builder subFactoriesBuilder) throws IOException {
    Rounding rounding = createRounding();
    ExtendedBounds roundedBounds = null;
    if (this.extendedBounds != null) {
        // parse any string bounds to longs and round
        roundedBounds = this.extendedBounds.parseAndValidate(name, context, config.format()).round(rounding);
    }
    return new DateHistogramAggregatorFactory(name, config, interval, dateHistogramInterval, offset, order, keyed, minDocCount, rounding, roundedBounds, context, parent, subFactoriesBuilder, metaData);
}
Also used : Rounding(org.elasticsearch.common.rounding.Rounding)

Example 2 with Rounding

use of org.elasticsearch.common.rounding.Rounding in project elasticsearch by elastic.

the class DateHistogramAggregationBuilder method createRounding.

private Rounding createRounding() {
    Rounding.Builder tzRoundingBuilder;
    if (dateHistogramInterval != null) {
        DateTimeUnit dateTimeUnit = DATE_FIELD_UNITS.get(dateHistogramInterval.toString());
        if (dateTimeUnit != null) {
            tzRoundingBuilder = Rounding.builder(dateTimeUnit);
        } else {
            // the interval is a time value?
            tzRoundingBuilder = Rounding.builder(TimeValue.parseTimeValue(dateHistogramInterval.toString(), null, getClass().getSimpleName() + ".interval"));
        }
    } else {
        // the interval is an integer time value in millis?
        tzRoundingBuilder = Rounding.builder(TimeValue.timeValueMillis(interval));
    }
    if (timeZone() != null) {
        tzRoundingBuilder.timeZone(timeZone());
    }
    Rounding rounding = tzRoundingBuilder.build();
    return rounding;
}
Also used : DateTimeUnit(org.elasticsearch.common.rounding.DateTimeUnit) Rounding(org.elasticsearch.common.rounding.Rounding)

Aggregations

Rounding (org.elasticsearch.common.rounding.Rounding)2 DateTimeUnit (org.elasticsearch.common.rounding.DateTimeUnit)1