public static K GetMax <T, K>(this AggregationsHelper aggs, Expression <Func <T, K> > fieldGetter) { var aggName = fieldGetter.GetAggName(AggType.Max); var maxAgg = aggs.Max(aggName); return(ValueAsUndType <K>(maxAgg)); }
private double[] GetNumbers(AggregationsHelper aggregations, IEnumerable <FieldAggregation> fields) { var results = new List <double>(); foreach (var field in fields) { switch (field.Type) { case FieldAggregationType.Average: results.Add(aggregations.Average(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Distinct: results.Add(aggregations.Cardinality(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Sum: results.Add(aggregations.Sum(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Min: results.Add(aggregations.Min(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Max: results.Add(aggregations.Max(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Last: // TODO: Populate with the last value. break; case FieldAggregationType.Term: var termResult = aggregations.Terms(field.Key); results.Add(termResult?.Items.Count > 0 ? termResult.Items[0].DocCount : 0); break; default: throw new InvalidOperationException($"Unknown FieldAggregation type: {field.Type}"); } } return(results.ToArray()); }
private double[] GetNumbers(AggregationsHelper aggregations, IEnumerable<FieldAggregation> fields) { var results = new List<double>(); foreach (var field in fields) { switch (field.Type) { case FieldAggregationType.Average: results.Add(aggregations.Average(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Distinct: results.Add(aggregations.Cardinality(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Sum: results.Add(aggregations.Sum(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Min: results.Add(aggregations.Min(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Max: results.Add(aggregations.Max(field.Key)?.Value.GetValueOrDefault() ?? 0); break; case FieldAggregationType.Last: // TODO: Populate with the last value. break; case FieldAggregationType.Term: var termResult = aggregations.Terms(field.Key); results.Add(termResult?.Items.Count > 0 ? termResult.Items[0].DocCount : 0); break; default: throw new InvalidOperationException($"Unknown FieldAggregation type: {field.Type}"); } } return results.ToArray(); }