1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| private async Task<AggregationDictionary> GenerateAggregationDictionary(string groupByName, Field field, int skip, int take) { var aggs = new AggregationDictionary(); await _elastic.IndexPutAsync<StringResponse>(IndexTypeName.PerformanceDaySnapshot, "_settings", PostData.String("{\"index.max_result_window\":99999,\"index.max_inner_result_window\":99999}")); await _elastic.IndexPutAsync<StringResponse>("/_cluster", "_settings", PostData.String("{ \"persistent\": { \"search.max_buckets\": 99999 }}")); var c_group = new AggregationDictionary { { "brokerInfo", new TopHitsAggregation("brokerInfo") { Size = 1, Sort = new List<ISort> { new SortField { Field = Infer.Field<PerformanceDaySnapshot>(p => p.Date), Order = SortOrder.Descending } }, Source = new SourceFilter { Includes = new[] { "userOrganization.brokerName", "userOrganization.storeId", "userOrganization.storeName", "userOrganization.storeLeaderName", "userOrganization.regionId", "userOrganization.regionName", "userOrganization.regionLeaderName", "userOrganization.bigRegionId", "userOrganization.bigRegionName", "userOrganization.bigRegionLeaderName" } } } }, { "trade", new TermsAggregation("trade") { Field = new Field("exportData.交易类型.keyword"), Aggregations = new TermsAggregation("performanceType") { Field = new Field("exportData.业绩类型.keyword"), Aggregations = new SumAggregation("performance", new Field("exportData.分边业绩")) { Missing = 0 } && new CardinalityAggregation("totalCount", Infer.Field<PerformanceDaySnapshot>(f=>f.JYCode)) && new TermsAggregation("listingCommission") { Field = Infer.Field<PerformanceDaySnapshot>(f=>f.JYCode), Aggregations = new TermsAggregation("group_by_date") { Field = Infer.Field<PerformanceDaySnapshot>(f=>f.Date), Order = new TermsOrder[] { new TermsOrder { Key = "max_date", Order = SortOrder.Descending } }, Aggregations = new MaxAggregation("max_date", Infer.Field<PerformanceDaySnapshot>(f=>f.Date)) && new SumAggregation("sum_order_receivable", new Field("exportData.订单总应收")) && new SumAggregation("sum_transaction_price", new Field("exportData.成交价格")) } && new SumBucketAggregation("sum_order_receivable", new SingleBucketsPath("group_by_date>sum_order_receivable")) && new SumBucketAggregation("sum_transaction_price", new SingleBucketsPath("group_by_date>sum_transaction_price")) } && new SumBucketAggregation("commission", new SingleBucketsPath("listingCommission>sum_order_receivable")) && new SumBucketAggregation("transactionPrice", new SingleBucketsPath("listingCommission>sum_transaction_price")) } } }, { "c_bucket_sort", new BucketSortAggregation("c_bucket_sort") { From = skip, Size = take } } };
aggs.Add("item_count", new CardinalityAggregation("item_count", new Field(groupByName))); aggs.Add(groupByName, new TermsAggregation(groupByName) { Field = field, Size = 10000, Aggregations = c_group }); return aggs; }
|