Example #1
0
        public static IReadOnlyCollection <DateHistogramBucket> GetDateHistogram <T>(this AggregationsHelper aggs,
                                                                                     Expression <Func <T, Object> > fieldGetter)
        {
            var histogramItem = aggs.DateHistogram(GetName(fieldGetter));

            return(histogramItem.Buckets);
        }
Example #2
0
        public static IList <HistogramItem> GetDateHistogram <T>(this AggregationsHelper aggs,
                                                                 Expression <Func <T, Object> > fieldGetter)
        {
            var histogramItem = aggs.DateHistogram(GetName(fieldGetter));

            return(histogramItem.Items);
        }
        public void AddAggregation_Helper()
        {
            var q = new Query <Customer>(true).SetSize(0);

            var aggr = AggregationsHelper
                       .DateHistogram <Customer>(ic => ic.Created, "week",
                                                 order: new AggsOrder(AggsOrderBy.Key, AggsOrderDirection.Desc))
                       .TermsAggregation("_id", order: new AggsOrder("sum", AggsOrderDirection.Desc));

            aggr.Aggregations["nested"].Add("sum",
                                            AggregationsHelper.SumAggregation <Customer>(ic =>
                                                                                         ic.Age));
            aggr.Aggregations["nested"].Add("above25percent_filter",
                                            AggregationsHelper.BucketSelector("sum", "sum", "params.sum > 180"));

            q.AddAggregation(aggr);

            var result = new DocumentSearch <Customer>().Search(_client, q);
            var b      = result.Aggregations["agg_DateHistogram"].Buckets.Where(x => x.Nested.Buckets.Any());

            Assert.IsNotNull(b);
        }
Example #4
0
        public void Ren3_gt25percent()
        {
            var gt25percent = new Query <IndexedClass>(true).SetSize(0);
            var aggr        = AggregationsHelper
                              .DateHistogram <IndexedClass>(ic => ic.Children.PropertyName(c => c.DateTimeNotNullable), "week",
                                                            order: new AggsOrder(AggsOrderBy.Key, AggsOrderDirection.Desc))
                              .TermsAggregation("_id", order: new AggsOrder("sum", AggsOrderDirection.Desc));

            aggr.Aggregations["nested"].Add("sum",
                                            AggregationsHelper.SumAggregation <IndexedClass>(ic =>
                                                                                             ic.Children.PropertyName(c => c.DateTimeNotNullable)));
            aggr.Aggregations["nested"].Add("above25percent_filter",
                                            AggregationsHelper.BucketSelector("sum", "sum", "params.sum > 2520"));

            gt25percent.NestedAggregation(ic => ic.Children, aggr);
            Assert.AreEqual(
                "{\"query\":{\"bool\":{}},\"aggs\":{\"nested_Children_0\":{\"nested\":{\"path\":\"Children\"},\"aggs\":{\"nested\":{\"date_histogram\":" +
                "{\"interval\":\"week\",\"field\":\"Children.DateTimeNotNullable\",\"order\":{\"_key\":\"desc\"}},\"aggs\":{\"nested\":{\"terms\":" +
                "{\"field\":\"_id\",\"order\":{\"sum\":\"desc\"}},\"aggs\":{\"sum\":{\"sum\":{\"field\":\"Children.DateTimeNotNullable\"}},\"above25percent_filter\":" +
                "{\"bucket_selector\":{\"buckets_path\":{\"sum\":\"sum\"},\"script\":\"params.sum > 2520\"}}}}}}}}},\"size\":0}",
                gt25percent.ToJson());
        }