Exemplo n.º 1
0
        /// <summary>
        /// Retrieves the terms aggregation just by it's name
        /// </summary>
        public static IReadOnlyCollection <KeyedBucket <string> > GetGroupBy(this AggregateDictionary aggs, string aggName)
        {
            aggs.CheckForAggregationInResult(aggName);
            var itemsTerms = aggs.Terms(aggName);

            return(itemsTerms.Buckets);
        }
Exemplo n.º 2
0
        private static IEnumerable <AggregationResult> GetAggregationResultsFrom(AggregateDictionary aggregations)
        {
            if (aggregations == null)
            {
                return(Enumerable.Empty <AggregationResult>());
            }

            var terms = aggregations.Terms(SubCategoriesAggregationName);

            if (terms == null)
            {
                return(Enumerable.Empty <AggregationResult>());
            }

            var items = terms.Buckets.Select(bucket => new AggregationResult
            {
                Code  = bucket.Key,
                Count = bucket.DocCount.GetValueOrDefault(0)
            });

            return(items);
        }
Exemplo n.º 3
0
        public static IEnumerable <V> GetDistinct <T, V>(this AggregateDictionary 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");
        }