public void Percentiles()
        {
            QueryBuilder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400 * 7));

            QueryBuilder.Aggregates.Add("95",
                                        new SubAggregate(
                                            new TermsAggregate("Request.ConsumerInfo.id"),
                                            "consumer",
                                            new PercentilesAggregate("TotalDuration", new [] { 95.0 })
                                            )
                                        );

            QueryBuilder.Aggregates.Add("99",
                                        new SubAggregate(
                                            new TermsAggregate("Request.ConsumerInfo.id"),
                                            "consumer",
                                            new PercentilesAggregate("TotalDuration", new[] { 99.0 })
                                            )
                                        );

            AggregateResult result = Client.ExecuteAggregate(QueryBuilder);

            /*
             * "99": {
             * "doc_count_error_upper_bound": 0,
             * "sum_other_doc_count": 75080,
             * "buckets": [
             *     {
             *     "key": "foo",
             *     "doc_count": 326120,
             *     "consumer": {
             *         "values": {
             *         "99.0": 1.23
             *         }
             *     }
             * },
             * ...
             * }
             */

            Assert.Greater(result.GetValues <dynamic>("99.buckets").Length, 0);
            Assert.Greater(result.GetValues <dynamic>("95.buckets").Length, 0);
        }
Esempio n. 2
0
        public void SimpleQuery()
        {
            QueryBuilder builder = new QueryBuilder();

            builder.Filtered.Filters.Add(FilterType.Must, new MovingTimeRange("@timestamp", 86400));
            HistogramAggregate aggregate = new HistogramAggregate("TotalDuration", "1000");

            builder.Aggregates.Add("test", aggregate);


            builder.PrintQuery(Client.IndexDescriptors);

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

            result.PrintResult();

            Assert.GreaterOrEqual(result.GetValues <object>("test.buckets").Length, 10);
            Assert.GreaterOrEqual(((JArray)resultDynamic.test.buckets).Count, 10);
        }
Esempio n. 3
0
        public void TermsAggregates()
        {
            QueryBuilder builder = new QueryBuilder();

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

            builder.Aggregates.Add("my_term", new TermsAggregate("EventType", 10)
            {
                Order = new OrderField()
            });

            builder.PrintQuery(Client.IndexDescriptors);

            AggregateResult result = Client.ExecuteAggregate(builder);

            result.PrintResult();


            Assert.Greater(result.GetValues <dynamic>("my_term.buckets").Length, 0);
        }