Beispiel #1
0
        public static AggregationDescriptor <T> IntoDateHistogram <T>(this AggregationDescriptor <T> innerAggregation,
                                                                      Expression <Func <T, Object> > fieldGetter, DateInterval interval) where T : class
        {
            AggregationDescriptor <T> v = new AggregationDescriptor <T>();
            var fieldName = GetName(fieldGetter);

            v.DateHistogram(fieldName, dr =>
            {
                DateHistogramAggregationDescriptor <T> dateAggDesc = new DateHistogramAggregationDescriptor <T>();
                dateAggDesc.Field(fieldGetter).Interval(interval);
                return(dateAggDesc.Aggregations(x => innerAggregation));
            });

            return(v);
        }
Beispiel #2
0
        public static DateHistogramAggregationDescriptor <T> AutoFormatTime <T>(this DateHistogramAggregationDescriptor <T> descriptor, FilterOptions.TimeUnit type) where T : class
        {
            switch (type)
            {
            case TimeUnit.Hour:
                descriptor.CalendarInterval(DateInterval.Hour).Format("HH");
                break;

            case TimeUnit.Month:
                descriptor.CalendarInterval(DateInterval.Month).Format("MM");
                break;

            case TimeUnit.Year:
                descriptor.CalendarInterval(DateInterval.Year).Format("YYYY");
                break;

            case TimeUnit.Day:
            default:
                descriptor.CalendarInterval(DateInterval.Day).Format("dd");
                break;
            }

            return(descriptor);
        }