public void DoubleAggregateGroup()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));

            var rangeGroup = new SubAggregate(
                new RangeAggregate(
                    "TotalDuration",
                    new Range(null, 10),
                    new Range(10, 20),
                    new Range(30, 40)
                    )
                );

            rangeGroup.Aggregates.Add("min", new MinAggregate("TotalDuration"));
            rangeGroup.Aggregates.Add("max", new MaxAggregate("TotalDuration"));
            builder.Aggregates.Add("range_group", rangeGroup);

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            Assert.IsNotNull(result.GetValue("range_group.buckets"));
        }
Example #2
0
        public void RangeGroup()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));

            var rangeAggregate = new RangeAggregate(
                "TotalDuration",
                new Range(null, 100),
                new Range(100, 500),
                new Range(500, null)
                );

            var rangeGroup = new SubAggregate(rangeAggregate);

            rangeGroup.Aggregates.Add("count", new CountAggregate("TotalDuration"));
            rangeGroup.Aggregates.Add("avg", new AverageAggregate("TotalDuration"));

            builder.Aggregates.Add("range_group", rangeGroup);

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            Assert.IsNotNull(result.GetValue("range_group.buckets"));
        }
Example #3
0
        public void CountAggregate()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));
            builder.Aggregates.Add("county", new CountAggregate("TotalDuration"));
            builder.Aggregates.Add("valuy", new ValueCountAggregate("TotalDuration"));

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            Assert.NotNull(result.GetValue("county.value"));
            Assert.AreEqual(result.GetValue <double>("county.value"), result.GetValue <double>("valuy.value"));
        }
Example #4
0
        public void PercentilesAggregate()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));
            builder.Aggregates.Add("my_result", new PercentilesAggregate("TotalDuration"));

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            double result25 = (double)result.GetValue <JObject>("my_result.values")["25.0"];
            double result50 = (double)result.GetValue <JObject>("my_result.values")["50.0"];

            Assert.Greater(result25, 0.0);
            Assert.Greater(result50, 0.0);
        }
Example #5
0
        public void MultipleAggregates()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must,
                                         new FixedTimeRange("@timestamp", DateTime.UtcNow.Yesterday(), DateTime.UtcNow));
            builder.Aggregates.Add("some_sum", new SumAggregate("TotalDuration"));
            builder.Aggregates.Add("serious_min", new MinAggregate("TotalDuration"));
            builder.Aggregates.Add("heavy_stats", new StatsAggregate("TotalDuration"));

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            result.GetValue("serious_min.value");
            result.GetValue("some_sum.value");
            result.GetValue("heavy_stats.count");
        }
Example #6
0
        public void StatsAggregate()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must,
                                         new FixedTimeRange("@timestamp", DateTime.UtcNow.Yesterday(), DateTime.UtcNow));
            builder.Aggregates.Add("my_result", new StatsAggregate("TotalDuration"));

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            result.GetValue("my_result.count");
            result.GetValue("my_result.min");
            result.GetValue("my_result.max");
            result.GetValue("my_result.avg");
            result.GetValue("my_result.sum");
        }
Example #7
0
        public void SumAggregate()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));
            builder.Aggregates.Add("my_result", new SumAggregate("TotalDuration"));

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            Assert.Greater(result.GetValue <double>("my_result.value"), 10000.0);
        }
Example #8
0
        public void MinAggregate()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));
            builder.Aggregates.Add("my_result", new MinAggregate("TotalDuration"));

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result        = Client.ExecuteAggregate(builder);
            dynamic         resultDynamic = result;

            result.PrintResult();

            Assert.IsNotNull(result.GetValue <double>("my_result.value"));
            Assert.IsNotNull(resultDynamic.my_result.value);
        }
        public void DoubleGroup()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));

            var termGroup  = new SubAggregate(new TermsAggregate("EventType"), "some_stats", new StatsAggregate("TotalDuration"));
            var rangeGroup = new SubAggregate(new RangeAggregate("TotalDuration", new Range(0, 10), new Range(10, 20)), "some_stats", new CountAggregate("TotalDuration"));

            builder.Aggregates.Add("term_group", termGroup);
            builder.Aggregates.Add("range_group", rangeGroup);

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();

            Assert.IsNotNull(result.GetValue("range_group.buckets"));
        }