/** * Get AggregationBuilder using dateRange with proper limits from parameters. * @param fieldName Name of field to time restrict * @param fromDate Start date for restriction * @param toDate End date for restriction * @return AggregationBuilder with required configuration */ private static DateRangeBuilder getDateRangeAggregationBuilder(String fieldName, String fromDate, String toDate) { DateRangeBuilder dateRangeAggregation = AggregationBuilders.dateRange("by_date").field(fieldName); if (fromDate == null && toDate != null) { dateRangeAggregation = dateRangeAggregation.addUnboundedTo(toDate); } else if (toDate == null && fromDate != null) { dateRangeAggregation = dateRangeAggregation.addUnboundedFrom(fromDate); } else { dateRangeAggregation = dateRangeAggregation.addRange(fromDate, toDate); } return dateRangeAggregation; }
/** * Get AggregationBuilder by country for limited time range. * @param fieldName Name of field containing country code. * @param classifierName Name of classifier * @param startDate Start date for creation of row * @param endDate End date for creation of row * @return AggregationBuilder with required configuration */ private static DateRangeBuilder getClassifierAggregationBuilderByCountry(String fieldName, String classifierName, String startDate, String endDate) { return getDateRangeAggregationBuilder("created_at", startDate, endDate) .subAggregation(getClassifierAggregationBuilderByCountry(fieldName, classifierName)); }
@Override public InternalDateRange create(String name, List<InternalDateRange.Bucket> ranges, DocValueFormat formatter, boolean keyed, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) { return new InternalDateRange(name, ranges, formatter, keyed, pipelineAggregators, metaData); }
@Override public Bucket createBucket(InternalAggregations aggregations, Bucket prototype) { return new Bucket(prototype.getKey(), prototype.internalFrom(), prototype.internalTo(), prototype.getDocCount(), aggregations, prototype.getKeyed(), prototype.getFormatter()); } }
@Override public InternalDateRange create(List<Bucket> ranges, InternalDateRange prototype) { return new InternalDateRange(prototype.name, ranges, prototype.format, prototype.keyed, prototype.pipelineAggregators(), prototype.metaData); }
/** * Same as {@link #addRange(String, DateTime, DateTime)} but the key will be * automatically generated based on <code>from</code> and <code>to</code>. */ public DateRangeAggregationBuilder addRange(DateTime from, DateTime to) { return addRange(null, from, to); }
@Override public InternalDateRange readResult(StreamInput in) throws IOException { InternalDateRange ranges = new InternalDateRange(); ranges.readFrom(in); return ranges; } };
/** * Same as {@link #addRange(String, Object, Object)} but the key will be * automatically generated based on <code>from</code> and <code>to</code>. */ public DateRangeBuilder addRange(Object from, Object to) { return addRange(null, from, to); }
@Override protected DateRangeAggregatorFactory innerBuild(SearchContext context, ValuesSourceConfig<Numeric> config, AggregatorFactory<?> parent, Builder subFactoriesBuilder) throws IOException { // We need to call processRanges here so they are parsed and we know whether `now` has been used before we make // the decision of whether to cache the request Range[] ranges = processRanges(context, config); if (ranges.length == 0) { throw new IllegalArgumentException("No [ranges] specified for the [" + this.getName() + "] aggregation"); } return new DateRangeAggregatorFactory(name, config, ranges, keyed, rangeFactory, context, parent, subFactoriesBuilder, metaData); } }
/** * Same as {@link #addUnboundedFrom(String, Object)} but the key will be * computed automatically. */ public DateRangeBuilder addUnboundedFrom(Object from) { return addUnboundedFrom(null, from); }
/** * Same as {@link #addUnboundedTo(String, Object)} but the key will be * computed automatically. */ public DateRangeBuilder addUnboundedTo(Object to) { return addUnboundedTo(null, to); }
/** * Same as {@link #addUnboundedFrom(String, double)} but the key will be * computed automatically. */ public DateRangeAggregationBuilder addUnboundedFrom(double from) { return addUnboundedFrom(null, from); }
/** * Create a new {@link DateRangeAggregationBuilder} aggregation with the * given name. */ public static DateRangeAggregationBuilder dateRange(String name) { return new DateRangeAggregationBuilder(name); }
/** * Same as {@link #addUnboundedTo(String, double)} but the key will be * computed automatically. */ public DateRangeAggregationBuilder addUnboundedTo(double to) { return addUnboundedTo(null, to); }
/** * Create a new {@link DateRangeBuilder} aggregation with the given name. */ public static DateRangeBuilder dateRange(String name) { return new DateRangeBuilder(name); }
@Override public InternalDateRange create(List<Bucket> ranges, InternalDateRange prototype) { return new InternalDateRange(prototype.name, ranges, prototype.formatter, prototype.keyed, prototype.pipelineAggregators(), prototype.metaData); }
/** * Same as {@link #addRange(String, double, double)} but the key will be * automatically generated based on <code>from</code> and <code>to</code>. */ public DateRangeAggregationBuilder addRange(double from, double to) { return addRange(null, from, to); }
/** * Get AggregationBuilder for specific time range. * @param classifierName Name of classifier * @param fromDate Start date for creation of row * @param toDate End date for creation of row * @return AggregationBuilder with required configuration */ private static DateRangeBuilder getClassifierAggregationBuilder(String classifierName, String fromDate, String toDate) { return getDateRangeAggregationBuilder("created_at", fromDate, toDate) .subAggregation(getClassifierAggregationBuilder(classifierName)); }
/** * Same as {@link #addUnboundedFrom(String, DateTime)} but the key will be * computed automatically. */ public DateRangeAggregationBuilder addUnboundedFrom(DateTime from) { return addUnboundedFrom(null, from); }
/** * Same as {@link #addRange(String, String, String)} but the key will be * automatically generated based on <code>from</code> and <code>to</code>. */ public DateRangeAggregationBuilder addRange(String from, String to) { return addRange(null, from, to); }