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(); }
private static Dictionary <string, long?> RetrieveAggregationElements(TermsAggregate <string> termsAggregate, bool useKeyAsString = false) { var aggregationResult = new Dictionary <string, long?>(); string keySelector(KeyedBucket <string> b) => useKeyAsString ? b.KeyAsString : b.Key; if (termsAggregate.Buckets != null) { foreach (var item in termsAggregate.Buckets) { aggregationResult.Add(keySelector(item), item.DocCount); } } return(aggregationResult); }