olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch

Home Page:https://olivere.github.io/elastic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

elastic.v7 NewBucketSelectorAggregation function have a bug,can not execute correct

henrY2Young opened this issue · comments

commented

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

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")))
commented

膜拜,太感谢了,关注了

Also notice the hundreds of tests. They illustrate how to use the library.