public static TermsAggregation TermsAggregation <T>(Expression <Func <T, object> > fieldExpression, AggsOrderBy orderBy, AggsOrderDirection direction, int?size = null, params IAggregation[] statAggregation) where T : new() { var fieldName = ExpressionHelper.GetPropertyName(fieldExpression); var termA = new TermsAggregation(fieldName, size, new AggsOrder(orderBy, direction)); foreach (var sa in statAggregation) { if (termA.Aggregations == null) { termA.Aggregations = new Dictionary <string, IAggregation>(); } if (sa.IsSubclassOfRawGeneric(typeof(RangeAggregation <>)) || sa is TermsAggregation) { termA.Aggregations["nested"] = sa; } else { termA.Aggregations[sa.GetType().Name.Replace("Aggregation", "")] = sa; } } return(termA); }
public static IAggregation BucketSort <T>(this IStatAggregation agg, Expression <Func <T, object> > fieldExpression, AggsOrderDirection direction, int?size = null, int?from = null) { var fieldName = ExpressionHelper.GetPropertyName(fieldExpression); agg.Aggregations[$"bucket_sort_{fieldName}"] = new BucketSortAggregation { BucketSort = new BucketSort { Size = size, From = from, Sorts = new[] { new Sort { [fieldName] = direction.ToString() } } } }; return(agg); }