Exemplo n.º 1
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"));
        }
        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"));
        }
        public void HeavySubAggregating()
        {
            var histogramAggregate    = new DateHistogramAggregate("@timestamp", "1d");
            var histogramSubAggregate = new SubAggregate(histogramAggregate);

            var totalSoldCarsAggregate = new ValueCountAggregate("TotalSoldCars");

            var countryTermsAggregate = new TermsAggregate("Country");
            var countrySubAggregate   = new SubAggregate(countryTermsAggregate);

            countrySubAggregate.Aggregates.Add("TotalSoldCars", totalSoldCarsAggregate);

            var carTypeTermsAggregate = new TermsAggregate("Type");
            var carTypeSubAggregate   = new SubAggregate(carTypeTermsAggregate);

            carTypeSubAggregate.Aggregates.Add("TotalSoldCarsOfType", totalSoldCarsAggregate);

            histogramSubAggregate.Aggregates.Add("CountrySubAggr", countrySubAggregate);

            countrySubAggregate.Aggregates.Add("CarTypeSubAggr", carTypeSubAggregate);


            QueryBuilder.Aggregates.Add("HistogramSubAggr", histogramSubAggregate);

            QueryBuilder.PrintQuery();

            AggregateResult result = Client.ExecuteAggregate(QueryBuilder);

            result.PrintResult();
        }
        public void GroupByRange()
        {
            QueryBuilder builder = new QueryBuilder();

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

            var groupQuery = new SubAggregate(new RangeAggregate("TotalDuration", new Range(0, 10), new Range(10, 20)), "some_stats", new CountAggregate("TotalDuration"));

            builder.Aggregates.Add("my_stats_group", groupQuery);

            builder.PrintQuery(Client.IndexDescriptors);

            dynamic result = Client.ExecuteAggregate(builder);

            Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));

            Assert.IsNotNull(result.my_stats_group.buckets);
        }
        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"));
        }