private static List <Aggs> ExtractPipeAggs(ISearchResponse <T> r) { var aggss = new List <Aggs>(); foreach (var ag in r.Aggregations) { var segs = ag.Key.Split('_'); switch (segs[0]) { case "area": var areas = r.Aggs.Terms("area"); var areaAggs = new Aggs("area"); foreach (var b in areas.Buckets) { if (b.Aggregations.Count > 0) { var agg = new Agg(); agg.count = b.DocCount ?? 0; agg.value = Math.Round(b.Average(segs[1] /*"ave_sal"*/).Value ?? 0, 2); areaAggs.aggs.Add(agg); } } aggss.Add(areaAggs); break; case "mon": var mons = r.Aggs.DateHistogram("mon"); var monAggs = new Aggs("mon"); foreach (var b in mons.Buckets) { if (b.Aggregations.Count > 0) { var agg = new Agg(); agg.count = b.DocCount ?? 0; agg.value = Math.Round(b.Average(/*"ave_sal"*/ segs[1]).Value ?? 0, 2); monAggs.aggs.Add(agg); } } aggss.Add(monAggs); break; } } return(aggss); }
private static List <Aggs> ExtractComAggs(ISearchResponse <T> r) { var aggs = new List <Aggs>(); foreach (var ag in r.Aggregations) { switch (ag.Key) { case "m_area": var areas = r.Aggs.Terms("m_area"); var areaAgg = new Aggs("m_area"); foreach (var b in areas.Buckets) { var aggItem = new Agg(); aggItem.count = b.DocCount ?? 0; areaAgg.aggs.Add(aggItem); } aggs.Add(areaAgg); break; case "oc_status": var statuss = r.Aggs.Terms("oc_status"); var statusAgg = new Aggs("oc_status"); foreach (var b in statuss.Buckets) { var aggItem = new Agg(); aggItem.count = b.DocCount ?? 0; statusAgg.aggs.Add(aggItem); } aggs.Add(statusAgg); break; case "gb_cat": var trades = r.Aggs.Terms("gb_cat"); var tradeAgg = new Aggs("gb_cat"); foreach (var b in trades.Buckets) { var aggItem = new Agg(); aggItem.count = b.DocCount ?? 0; tradeAgg.aggs.Add(aggItem); } aggs.Add(tradeAgg); break; case "od_regdate": var dates = r.Aggs.DateHistogram("od_regdate"); var dateAgg = new Aggs("od_regdate"); foreach (var b in dates.Buckets) { var aggItem = new Agg(); dateAgg.aggs.Add(aggItem); } aggs.Add(dateAgg); break; case "od_regm": var regms = r.Aggs.DateRange("od_regm"); var regmAgg = new Aggs("od_regm"); foreach (var b in regms.Buckets) { var aggItem = new Agg(); aggItem.count = b.DocCount; regmAgg.aggs.Add(aggItem); } aggs.Add(regmAgg); break; } } return(aggs); }