Пример #1
0
        private void SetAggregation()
        {
            foreach (var item in aggregations)
            {
                switch (item.Method)
                {
                case "Count":
                    AggregationBase = new ValueCountAggregation(item.AggName, item.Field);
                    break;

                case "Min":
                    AggregationBase = new MinAggregation(item.AggName, item.Field);
                    break;

                case "Max":
                    AggregationBase = new MaxAggregation(item.AggName, item.Field);
                    break;

                case "Sum":
                    AggregationBase = new SumAggregation(item.AggName, item.Field);
                    break;

                case "Average":
                    AggregationBase = new AverageAggregation(item.AggName, item.Field);
                    break;

                default:
                    break;
                }
            }

            _searchRequest.Aggregations = ObterAgrupamentoNest(fieldsGroupBy, AggregationBase);
        }
Пример #2
0
        private static AggregationBase CreateFacet(AggregationBase primaryAggregation, FacetFilters[] facetsFilters)
        {
            var primaryAggregationName = ((IAggregation)primaryAggregation).Name;

            return(new FilterAggregation("facet_" + primaryAggregationName)
            {
                Filter = CreateQuery(facetsFilters, Regex.Replace(primaryAggregationName, @"\d\d\d", "")),
                Aggregations = primaryAggregation
            });
        }
    //internal override void WrapInContainer(AggregationContainer container) { }

    private void AddAggregation(AggregationBase agg)
    {
        switch (agg)
        {
        case null:
            return;

        case AggregationCombinator combinator when combinator.Aggregations.Any():
            Aggregations.AddRange(combinator.Aggregations);

            break;

        default:
            Aggregations.Add(agg);
            break;
        }
    }
Пример #4
0
        private AggregationBase GetParentContainer(IQueryNode node, IQueryVisitorContext context)
        {
            AggregationBase container   = null;
            var             currentNode = node;

            while (container == null && currentNode != null)
            {
                IQueryNode n = currentNode;
                container = n.GetAggregation(() => {
                    var result = n.GetDefaultAggregation(context);
                    if (result != null)
                    {
                        n.SetAggregation(result);
                    }

                    return(result);
                }) as AggregationBase;

                if (currentNode.Parent != null)
                {
                    currentNode = currentNode.Parent;
                }
                else
                {
                    break;
                }
            }

            if (container == null)
            {
                container = new ChildrenAggregation(null, null);
                currentNode.SetAggregation(container);
            }

            return(container);
        }
 public AggregationContainer(AggregationBase variant) => Variant = variant ?? throw new ArgumentNullException(nameof(variant));
 public static void SetAggregation(this IQueryNode node, AggregationBase aggregation)
 {
     node.Data[AggregationKey] = aggregation;
 }
Пример #7
0
        public AggregationDictionary ObterAgrupamentoNest(IEnumerable <GroupBy> agrupamentos, AggregationBase aggregations = null)
        {
            foreach (var aggr in agrupamentos)
            {
                //Tipos de agrupamento
                if (aggr.PropertyType == typeof(DateTime) ||
                    aggr.PropertyType == typeof(DateTime?))
                {
                    var dateHistAgg = new DateHistogramAggregation(aggr.Field)
                    {
                        Missing = (DateTime?)null,//(DateTime?)aggr.Missing,
                        Field   = aggr.Field,
                        //Aggregations = ((aggregations != null) ? aggregations : null),
                        Interval             = DateInterval.Day,
                        MinimumDocumentCount = 1,
                        //Script = (!string.IsNullOrWhiteSpace(aggr.Script)) ? new InlineScript(aggr.Script) : null
                    };

                    if (aggregations != null)
                    {
                        dateHistAgg.Aggregations = aggregations;
                    }

                    aggregations = dateHistAgg;
                }
                else
                {
                    var termsAgg = new TermsAggregation(aggr.Field)
                    {
                        Field = aggr.Field,
                        //Aggregations = ((aggregations != null) ? aggregations : null),
                        Size = int.MaxValue,
                        //Missing = null,//aggr.Missing,
                        MinimumDocumentCount = 1,
                        //Script = (!string.IsNullOrWhiteSpace(aggr.Script)) ? new InlineScript(aggr.Script) : null
                    };

                    if (aggregations != null)
                    {
                        termsAgg.Aggregations = aggregations;
                    }


                    aggregations = termsAgg;
                }
            }
            return(aggregations);
        }
 public AggregationCombinator(string name, AggregationBase left, AggregationBase right) : base(name)
 {
     AddAggregation(left);
     AddAggregation(right);
 }