Closed henrY2Young closed 2 years ago
move SubAggregation("bucket_filter", ...)
to outer NewTermsAggregation
, like this
mainAgg := elastic.NewTermsAggregation().Field("userid").Size(1000000)
mainAgg.SubAggregation("sum_order",elastic.NewSumAggregation().Field("orders_times_all"))
mainAgg.SubAggregation("bucket_filter",elastic.NewBucketSelectorAggregation().AddBucketsPath("sum_order","sum_order").Script(elastic.NewScript("params.sum_order>1")))
膜拜,太感谢了,关注了
Also notice the hundreds of tests. They illustrate how to use the library.
this is my code
agg:=elastic.NewTermsAggregation().Field("userid").Size(1000000). SubAggregation("sum_order",elastic.NewSumAggregation().Field("orders_times_all"). SubAggregation("bucket_filter",elastic.NewBucketSelectorAggregation().AddBucketsPath("sum_order","sum_order").Script(elastic.NewScript("params.sum_order>1"))))
this is source() out
"aggregations": { "sum_order": { "aggregations": { "bucket_filter": { "bucket_selector": { "buckets_path": { "sum_order": "sum_order" }, "script": { "source": "params.sum_order\u003e1" } } } }, "sum": { "field": "orders_times_all" } } }, "terms": { "field": "userid", "size": 1000000 } }
but es has a panic
elastic: Error 500 (Internal Server Error): Aggregator [sum_order] of type [sum] cannot accept sub-aggregations [type=aggregation_initialization_exception]
Am I using it the wrong way? OR this is a bug