public void TermsAggregation_RangeAggregation_FromHelper()
        {
            var agg = AggregationsHelper.RangeAggregation <Event, double?>(x => x.Duration,
                                                                           new RangeAggrValue <double?> {
                From = 2 * 60, Key = "Above120"
            });

            agg.Aggregations = new Dictionary <string, IAggregation>();
            agg.CardinalityAggregation <Event>(ci => ci.AssetGuid).TopHitsAggregation(ParameterHelper.Sort(
                                                                                          new KeyValuePair <Expression <Func <Event, object> >, AggsOrderDirection>(ic => ic.Start,
                                                                                                                                                                    AggsOrderDirection.Desc)), ParameterHelper.Excludes <Event>(ic => ic.StSrid));
            var termsAgg = AggregationsHelper.TermsAggregation <Event>(x => x.AssetGuid, 1000, null, agg,
                                                                       AggregationsHelper.BucketSelector("count", "nested._bucket_count", "params.count > 0"));


            var q2 = new Query <Event>().Match("EarthFault", e => e.Type)
                     .DateHistogramAggregation(x => x.Start, "week", 1, termsAgg)
                     .SetSize(0);

            var nested = q2.Aggregations.FirstOrDefault().Value.Aggregations.FirstOrDefault().Value.Aggregations.FirstOrDefault().Key;
            var n      = q2.Aggregations.FirstOrDefault().Value.Aggregations.FirstOrDefault().Key;

            Assert.AreEqual("nested", nested);
            Assert.AreEqual("nested", n);
        }
Esempio n. 2
0
        public void BucketSelector_Multiple()
        {
            var q = new Query <EarthFaultEvent>()
                    .TermsAggregation(x => x.Type, null,
                                      AggregationsHelper.BucketSelector("max", "Max", $"params.max < 99"),
                                      AggregationsHelper.BucketSelector("max", "Max", $"params.max > 0"));

            var qJson = q.ToJson();

            var matches = Regex.Matches(qJson, "BucketSelector_").Count;

            Assert.AreEqual(2, matches);
        }
        public void BucketSelector_Terms()
        {
            var agg = AggregationsHelper.RangeAggregation <IndexedClass, double?>(x => x.SomeNumber,
                                                                                  new RangeAggrValue <double?> {
                From = 2 * 60, Key = "Above120"
            });

            agg.Aggregations = new Dictionary <string, IAggregation>();
            agg.CardinalityAggregation <IndexedClass>(ci => ci.ObjectId).TopHitsAggregation(ParameterHelper.Sort(
                                                                                                new KeyValuePair <Expression <Func <IndexedClass, object> >, AggsOrderDirection>(ic => ic.DateTimeNotNullable,
                                                                                                                                                                                 AggsOrderDirection.Desc)), ParameterHelper.Excludes <IndexedClass>(ic => ic.SomeNumber));



            var q2 = new Query <IndexedClass>(true).Match("EarthFault", e => e.AString)
                     .TermsAggregation(x => x.ObjectId, 100, agg, AggregationsHelper.BucketSelector("count", "nested._bucket_count", "params.count > 0"))
                     .SetSize(0);

            Assert.AreEqual("nested", q2.Aggregations.FirstOrDefault().Value.Aggregations.Keys.FirstOrDefault());
        }
        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);
        }
Esempio n. 5
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());
        }