Skip to content

Commit d4da960

Browse files
Zyqsempaiolivere
authored andcommitted
Remove sub-aggregations from pipeline aggs
Pipeline aggregations [cannot have sub-aggregations](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-aggregations-pipeline.html#search-aggregations-pipeline), so we should remove them all. See #734 and #735
1 parent 95391f3 commit d4da960

13 files changed

+29
-300
lines changed

search_aggs_pipeline_avg_bucket.go

+3-24
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ type AvgBucketAggregation struct {
1515
format string
1616
gapPolicy string
1717

18-
subAggregations map[string]Aggregation
19-
meta map[string]interface{}
20-
bucketsPaths []string
18+
meta map[string]interface{}
19+
bucketsPaths []string
2120
}
2221

2322
// NewAvgBucketAggregation creates and initializes a new AvgBucketAggregation.
2423
func NewAvgBucketAggregation() *AvgBucketAggregation {
2524
return &AvgBucketAggregation{
26-
subAggregations: make(map[string]Aggregation),
27-
bucketsPaths: make([]string, 0),
25+
bucketsPaths: make([]string, 0),
2826
}
2927
}
3028

@@ -52,12 +50,6 @@ func (a *AvgBucketAggregation) GapSkip() *AvgBucketAggregation {
5250
return a
5351
}
5452

55-
// SubAggregation adds a sub-aggregation to this aggregation.
56-
func (a *AvgBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *AvgBucketAggregation {
57-
a.subAggregations[name] = subAggregation
58-
return a
59-
}
60-
6153
// Meta sets the meta data to be included in the aggregation response.
6254
func (a *AvgBucketAggregation) Meta(metaData map[string]interface{}) *AvgBucketAggregation {
6355
a.meta = metaData
@@ -91,19 +83,6 @@ func (a *AvgBucketAggregation) Source() (interface{}, error) {
9183
params["buckets_path"] = a.bucketsPaths
9284
}
9385

94-
// AggregationBuilder (SubAggregations)
95-
if len(a.subAggregations) > 0 {
96-
aggsMap := make(map[string]interface{})
97-
source["aggregations"] = aggsMap
98-
for name, aggregate := range a.subAggregations {
99-
src, err := aggregate.Source()
100-
if err != nil {
101-
return nil, err
102-
}
103-
aggsMap[name] = src
104-
}
105-
}
106-
10786
// Add Meta data if available
10887
if len(a.meta) > 0 {
10988
source["meta"] = a.meta

search_aggs_pipeline_bucket_script.go

-21
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ type BucketScriptAggregation struct {
1616
gapPolicy string
1717
script *Script
1818

19-
subAggregations map[string]Aggregation
2019
meta map[string]interface{}
2120
bucketsPathsMap map[string]string
2221
}
2322

2423
// NewBucketScriptAggregation creates and initializes a new BucketScriptAggregation.
2524
func NewBucketScriptAggregation() *BucketScriptAggregation {
2625
return &BucketScriptAggregation{
27-
subAggregations: make(map[string]Aggregation),
2826
bucketsPathsMap: make(map[string]string),
2927
}
3028
}
@@ -59,12 +57,6 @@ func (a *BucketScriptAggregation) Script(script *Script) *BucketScriptAggregatio
5957
return a
6058
}
6159

62-
// SubAggregation adds a sub-aggregation to this aggregation.
63-
func (a *BucketScriptAggregation) SubAggregation(name string, subAggregation Aggregation) *BucketScriptAggregation {
64-
a.subAggregations[name] = subAggregation
65-
return a
66-
}
67-
6860
// Meta sets the meta data to be included in the aggregation response.
6961
func (a *BucketScriptAggregation) Meta(metaData map[string]interface{}) *BucketScriptAggregation {
7062
a.meta = metaData
@@ -110,19 +102,6 @@ func (a *BucketScriptAggregation) Source() (interface{}, error) {
110102
params["buckets_path"] = a.bucketsPathsMap
111103
}
112104

113-
// AggregationBuilder (SubAggregations)
114-
if len(a.subAggregations) > 0 {
115-
aggsMap := make(map[string]interface{})
116-
source["aggregations"] = aggsMap
117-
for name, aggregate := range a.subAggregations {
118-
src, err := aggregate.Source()
119-
if err != nil {
120-
return nil, err
121-
}
122-
aggsMap[name] = src
123-
}
124-
}
125-
126105
// Add Meta data if available
127106
if len(a.meta) > 0 {
128107
source["meta"] = a.meta

search_aggs_pipeline_bucket_selector.go

-21
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ type BucketSelectorAggregation struct {
1818
gapPolicy string
1919
script *Script
2020

21-
subAggregations map[string]Aggregation
2221
meta map[string]interface{}
2322
bucketsPathsMap map[string]string
2423
}
2524

2625
// NewBucketSelectorAggregation creates and initializes a new BucketSelectorAggregation.
2726
func NewBucketSelectorAggregation() *BucketSelectorAggregation {
2827
return &BucketSelectorAggregation{
29-
subAggregations: make(map[string]Aggregation),
3028
bucketsPathsMap: make(map[string]string),
3129
}
3230
}
@@ -61,12 +59,6 @@ func (a *BucketSelectorAggregation) Script(script *Script) *BucketSelectorAggreg
6159
return a
6260
}
6361

64-
// SubAggregation adds a sub-aggregation to this aggregation.
65-
func (a *BucketSelectorAggregation) SubAggregation(name string, subAggregation Aggregation) *BucketSelectorAggregation {
66-
a.subAggregations[name] = subAggregation
67-
return a
68-
}
69-
7062
// Meta sets the meta data to be included in the aggregation response.
7163
func (a *BucketSelectorAggregation) Meta(metaData map[string]interface{}) *BucketSelectorAggregation {
7264
a.meta = metaData
@@ -112,19 +104,6 @@ func (a *BucketSelectorAggregation) Source() (interface{}, error) {
112104
params["buckets_path"] = a.bucketsPathsMap
113105
}
114106

115-
// AggregationBuilder (SubAggregations)
116-
if len(a.subAggregations) > 0 {
117-
aggsMap := make(map[string]interface{})
118-
source["aggregations"] = aggsMap
119-
for name, aggregate := range a.subAggregations {
120-
src, err := aggregate.Source()
121-
if err != nil {
122-
return nil, err
123-
}
124-
aggsMap[name] = src
125-
}
126-
}
127-
128107
// Add Meta data if available
129108
if len(a.meta) > 0 {
130109
source["meta"] = a.meta

search_aggs_pipeline_cumulative_sum.go

+3-24
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ package elastic
1414
type CumulativeSumAggregation struct {
1515
format string
1616

17-
subAggregations map[string]Aggregation
18-
meta map[string]interface{}
19-
bucketsPaths []string
17+
meta map[string]interface{}
18+
bucketsPaths []string
2019
}
2120

2221
// NewCumulativeSumAggregation creates and initializes a new CumulativeSumAggregation.
2322
func NewCumulativeSumAggregation() *CumulativeSumAggregation {
2423
return &CumulativeSumAggregation{
25-
subAggregations: make(map[string]Aggregation),
26-
bucketsPaths: make([]string, 0),
24+
bucketsPaths: make([]string, 0),
2725
}
2826
}
2927

@@ -32,12 +30,6 @@ func (a *CumulativeSumAggregation) Format(format string) *CumulativeSumAggregati
3230
return a
3331
}
3432

35-
// SubAggregation adds a sub-aggregation to this aggregation.
36-
func (a *CumulativeSumAggregation) SubAggregation(name string, subAggregation Aggregation) *CumulativeSumAggregation {
37-
a.subAggregations[name] = subAggregation
38-
return a
39-
}
40-
4133
// Meta sets the meta data to be included in the aggregation response.
4234
func (a *CumulativeSumAggregation) Meta(metaData map[string]interface{}) *CumulativeSumAggregation {
4335
a.meta = metaData
@@ -68,19 +60,6 @@ func (a *CumulativeSumAggregation) Source() (interface{}, error) {
6860
params["buckets_path"] = a.bucketsPaths
6961
}
7062

71-
// AggregationBuilder (SubAggregations)
72-
if len(a.subAggregations) > 0 {
73-
aggsMap := make(map[string]interface{})
74-
source["aggregations"] = aggsMap
75-
for name, aggregate := range a.subAggregations {
76-
src, err := aggregate.Source()
77-
if err != nil {
78-
return nil, err
79-
}
80-
aggsMap[name] = src
81-
}
82-
}
83-
8463
// Add Meta data if available
8564
if len(a.meta) > 0 {
8665
source["meta"] = a.meta

search_aggs_pipeline_derivative.go

+3-24
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ type DerivativeAggregation struct {
1616
gapPolicy string
1717
unit string
1818

19-
subAggregations map[string]Aggregation
20-
meta map[string]interface{}
21-
bucketsPaths []string
19+
meta map[string]interface{}
20+
bucketsPaths []string
2221
}
2322

2423
// NewDerivativeAggregation creates and initializes a new DerivativeAggregation.
2524
func NewDerivativeAggregation() *DerivativeAggregation {
2625
return &DerivativeAggregation{
27-
subAggregations: make(map[string]Aggregation),
28-
bucketsPaths: make([]string, 0),
26+
bucketsPaths: make([]string, 0),
2927
}
3028
}
3129

@@ -60,12 +58,6 @@ func (a *DerivativeAggregation) Unit(unit string) *DerivativeAggregation {
6058
return a
6159
}
6260

63-
// SubAggregation adds a sub-aggregation to this aggregation.
64-
func (a *DerivativeAggregation) SubAggregation(name string, subAggregation Aggregation) *DerivativeAggregation {
65-
a.subAggregations[name] = subAggregation
66-
return a
67-
}
68-
6961
// Meta sets the meta data to be included in the aggregation response.
7062
func (a *DerivativeAggregation) Meta(metaData map[string]interface{}) *DerivativeAggregation {
7163
a.meta = metaData
@@ -102,19 +94,6 @@ func (a *DerivativeAggregation) Source() (interface{}, error) {
10294
params["buckets_path"] = a.bucketsPaths
10395
}
10496

105-
// AggregationBuilder (SubAggregations)
106-
if len(a.subAggregations) > 0 {
107-
aggsMap := make(map[string]interface{})
108-
source["aggregations"] = aggsMap
109-
for name, aggregate := range a.subAggregations {
110-
src, err := aggregate.Source()
111-
if err != nil {
112-
return nil, err
113-
}
114-
aggsMap[name] = src
115-
}
116-
}
117-
11897
// Add Meta data if available
11998
if len(a.meta) > 0 {
12099
source["meta"] = a.meta

search_aggs_pipeline_max_bucket.go

+3-24
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ type MaxBucketAggregation struct {
1616
format string
1717
gapPolicy string
1818

19-
subAggregations map[string]Aggregation
20-
meta map[string]interface{}
21-
bucketsPaths []string
19+
meta map[string]interface{}
20+
bucketsPaths []string
2221
}
2322

2423
// NewMaxBucketAggregation creates and initializes a new MaxBucketAggregation.
2524
func NewMaxBucketAggregation() *MaxBucketAggregation {
2625
return &MaxBucketAggregation{
27-
subAggregations: make(map[string]Aggregation),
28-
bucketsPaths: make([]string, 0),
26+
bucketsPaths: make([]string, 0),
2927
}
3028
}
3129

@@ -53,12 +51,6 @@ func (a *MaxBucketAggregation) GapSkip() *MaxBucketAggregation {
5351
return a
5452
}
5553

56-
// SubAggregation adds a sub-aggregation to this aggregation.
57-
func (a *MaxBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *MaxBucketAggregation {
58-
a.subAggregations[name] = subAggregation
59-
return a
60-
}
61-
6254
// Meta sets the meta data to be included in the aggregation response.
6355
func (a *MaxBucketAggregation) Meta(metaData map[string]interface{}) *MaxBucketAggregation {
6456
a.meta = metaData
@@ -92,19 +84,6 @@ func (a *MaxBucketAggregation) Source() (interface{}, error) {
9284
params["buckets_path"] = a.bucketsPaths
9385
}
9486

95-
// AggregationBuilder (SubAggregations)
96-
if len(a.subAggregations) > 0 {
97-
aggsMap := make(map[string]interface{})
98-
source["aggregations"] = aggsMap
99-
for name, aggregate := range a.subAggregations {
100-
src, err := aggregate.Source()
101-
if err != nil {
102-
return nil, err
103-
}
104-
aggsMap[name] = src
105-
}
106-
}
107-
10887
// Add Meta data if available
10988
if len(a.meta) > 0 {
11089
source["meta"] = a.meta

search_aggs_pipeline_min_bucket.go

+3-24
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ type MinBucketAggregation struct {
1616
format string
1717
gapPolicy string
1818

19-
subAggregations map[string]Aggregation
20-
meta map[string]interface{}
21-
bucketsPaths []string
19+
meta map[string]interface{}
20+
bucketsPaths []string
2221
}
2322

2423
// NewMinBucketAggregation creates and initializes a new MinBucketAggregation.
2524
func NewMinBucketAggregation() *MinBucketAggregation {
2625
return &MinBucketAggregation{
27-
subAggregations: make(map[string]Aggregation),
28-
bucketsPaths: make([]string, 0),
26+
bucketsPaths: make([]string, 0),
2927
}
3028
}
3129

@@ -53,12 +51,6 @@ func (a *MinBucketAggregation) GapSkip() *MinBucketAggregation {
5351
return a
5452
}
5553

56-
// SubAggregation adds a sub-aggregation to this aggregation.
57-
func (a *MinBucketAggregation) SubAggregation(name string, subAggregation Aggregation) *MinBucketAggregation {
58-
a.subAggregations[name] = subAggregation
59-
return a
60-
}
61-
6254
// Meta sets the meta data to be included in the aggregation response.
6355
func (a *MinBucketAggregation) Meta(metaData map[string]interface{}) *MinBucketAggregation {
6456
a.meta = metaData
@@ -92,19 +84,6 @@ func (a *MinBucketAggregation) Source() (interface{}, error) {
9284
params["buckets_path"] = a.bucketsPaths
9385
}
9486

95-
// AggregationBuilder (SubAggregations)
96-
if len(a.subAggregations) > 0 {
97-
aggsMap := make(map[string]interface{})
98-
source["aggregations"] = aggsMap
99-
for name, aggregate := range a.subAggregations {
100-
src, err := aggregate.Source()
101-
if err != nil {
102-
return nil, err
103-
}
104-
aggsMap[name] = src
105-
}
106-
}
107-
10887
// Add Meta data if available
10988
if len(a.meta) > 0 {
11089
source["meta"] = a.meta

0 commit comments

Comments
 (0)