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 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 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 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); }
public void FilterByLucene() { var filters = new FiltersAggregate(); filters.Add("Success", new LuceneFilter("Level:Info")); filters.Add("Error", new LuceneFilter("Level:Error")); //var filtersSubAggregate = new SubAggregate(filters, "counts", new CountAggregate("@timestamp")); QueryBuilder.Aggregates.Add("requests", filters); QueryBuilder.PrintQuery(); AggregateResult result = Client.ExecuteAggregate(QueryBuilder); result.PrintResult(); }
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 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")); }
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); }
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); }
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")); }
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); }
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"); }
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"); }