/// <summary> /// Retrieves the terms aggregation just by it's name /// </summary> public static IReadOnlyCollection <KeyedBucket <string> > GetGroupBy(this AggregationsHelper aggs, string aggName) { aggs.CheckForAggregationInResult(aggName); var itemsTerms = aggs.Terms(aggName); return(itemsTerms.Buckets); }
public static IEnumerable <KeyItem> GetGroupBy <T>(this AggregationsHelper aggs, Expression <Func <T, Object> > fieldGetter) { var aggName = fieldGetter.GetAggName(AggType.GroupBy); var itemsTerms = aggs.Terms(aggName); return(itemsTerms.Items); }
public static IEnumerable <K> GetGroupBy <T, K>(this AggregationsHelper aggs, Expression <Func <T, Object> > fieldGetter, Func <KeyedBucket, K> objectTransformer) { var aggName = fieldGetter.GetAggName(AggType.GroupBy); var itemsTerms = aggs.Terms(aggName); return(itemsTerms.Buckets.Select(objectTransformer)); }
public static IDictionary <String, K> GetDictionary <T, K>(this AggregationsHelper aggs, Expression <Func <T, Object> > fieldGetter, Func <KeyItem, K> objectTransformer) { var aggName = fieldGetter.GetAggName(AggType.GroupBy); var itemsTerms = aggs.Terms(aggName); return(itemsTerms.Items.ToDictionary(x => x.Key, objectTransformer)); }
private static IEnumerable <AggregationResult> GetAggregationResultsFrom(AggregationsHelper aggregations) { return (aggregations.Terms(FrameworkAggregationName) .Items.Select(bucket => new AggregationResult { Code = bucket.Key, Count = bucket.DocCount })); }
public static IDictionary <V, KeyedBucket> GetDictionary <T, V>(this AggregationsHelper aggs, Expression <Func <T, Object> > fieldGetter) where V : struct, IConvertible { var aggName = fieldGetter.GetAggName(AggType.GroupBy); var itemsTerms = aggs.Terms(aggName); if ((typeof(V).IsEnum)) { return(itemsTerms.Buckets.ToDictionary(x => Filters.Parse <V>(x.Key))); } return(itemsTerms.Buckets.ToDictionary(x => (V)Convert.ChangeType(x.Key, typeof(V)))); }
public static K GetFirstBy <T, K>(this AggregationsHelper aggs, Expression <Func <T, K> > fieldGetter, Expression <Func <T, object> > filterRule = null) { var aggName = fieldGetter.GetAggName(AggType.Sum); if (filterRule == null) { var terms = aggs.Terms(aggName); return(Filters.StringToAnything <K>(terms.Items[0].Key)); } else { var filterName = filterRule.GenerateFilterName(); var filterAgg = aggs.Filter(filterName); var termsAgg = filterAgg.Terms(aggName); return(Filters.StringToAnything <K>(termsAgg.Items[0].Key)); } }
private static IEnumerable <AggregationResult> GetAggregationResultsFrom(AggregationsHelper aggregations) { var terms = aggregations.Terms(SubCategoriesAggregationName); if (terms == null) { return(Enumerable.Empty <AggregationResult>()); } var items = terms.Items.Select(bucket => new AggregationResult { Code = bucket.Key, Count = bucket.DocCount }); return(items); }
public static IEnumerable <V> GetDistinct <T, V>(this AggregationsHelper aggs, Expression <Func <T, V> > fieldGetter) { var aggName = fieldGetter.GetAggName(AggType.Distinct); var itemsTerms = aggs.Terms(aggName); if ((typeof(V).IsEnum)) { return(itemsTerms.Items.Select((x => Filters.Parse <V>(x.Key)))); } else if (typeof(V) == typeof(string)) { return(itemsTerms.Items.Select((x => (V)(object)(x.Key)))); } else { return(itemsTerms.Items.Select((x => (V)(object)(x.Key)))); } }
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()); }
public static IEnumerable <V> GetDistinct <T, V>(this AggregationsHelper aggs, Expression <Func <T, V> > fieldGetter) { var aggName = fieldGetter.GetAggName(AggType.Distinct); var itemsTerms = aggs.Terms(aggName); var targetType = typeof(V); if (targetType.IsEnum) { return(itemsTerms.Buckets.Select((x => Filters.Parse <V>(x.Key)))); } if (targetType == typeof(string)) { return(itemsTerms.Buckets.Select(x => x.Key).Cast <V>()); } if (targetType == typeof(long) || targetType == typeof(int)) { return(itemsTerms.Buckets.Select(x => long.Parse(x.Key)).Cast <V>()); } throw new NotImplementedException("You can get only distinct values of Strings, Enums, ints or long"); }
public static IEnumerable <KeyItem> GetGroupBy(this AggregationsHelper aggs, string key) { var itemsTerms = aggs.Terms(key); return(itemsTerms.Items); }
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(); }