@@ -38,21 +38,23 @@ type Aggregation interface {
38
38
39
39
const (
40
40
// Metric types
41
- MetricAvg = "avg"
42
- MetricSum = "sum"
43
- MetricMin = "min"
44
- MetricMax = "max"
45
- MetricCount = "count"
41
+ MetricAvg = "avg"
42
+ MetricSum = "sum"
43
+ MetricMin = "min"
44
+ MetricMax = "max"
45
+ MetricCount = "count"
46
46
MetricPercentiles = "percentiles"
47
- MetricTopHits = "top_hits"
47
+ MetricTopHits = "top_hits"
48
48
MetricCardinality = "cardinality"
49
- MetricMedian = "median_absolute_deviation"
49
+ MetricMedian = "median_absolute_deviation"
50
50
// Bucket types
51
51
MetricBucketTerms = "terms"
52
52
MetricBucketDateHistogram = "date_histogram"
53
- MetricBucketFilter = "filter"
53
+ MetricBucketFilter = "filter"
54
+ MetricDateRange = "date_range"
54
55
// Pipeline types
55
56
MetricPipelineDerivative = "derivative"
57
+ MetricSumBucket = "sum_bucket"
56
58
)
57
59
58
60
// baseAggregation provides common functionality for all aggregation types,
@@ -61,7 +63,7 @@ type baseAggregation struct {
61
63
// NestedAggs holds any sub-aggregations.
62
64
NestedAggs map [string ]Aggregation `json:"-"`
63
65
// Params can hold additional parameters specific to certain aggregation types.
64
- Params map [string ]interface {} `json:"-"`
66
+ Params map [string ]interface {} `json:"-"`
65
67
}
66
68
67
69
// AddNested adds a sub-aggregation to the base aggregation.
@@ -105,9 +107,9 @@ func (a *TermsAggregation) AddNested(name string, sub Aggregation) Aggregation {
105
107
106
108
// MetricAggregation represents a single-value metric calculation (avg, sum, etc.).
107
109
type MetricAggregation struct {
108
- baseAggregation // Although metrics rarely have sub-aggs in ES, the model allows it.
109
- Type string `mapstructure:"-"` // Type of metric: "avg", "sum", etc. Not part of the decoded structure.
110
- Field string
110
+ baseAggregation // Although metrics rarely have sub-aggs in ES, the model allows it.
111
+ Type string `mapstructure:"-"` // Type of metric: "avg", "sum", etc. Not part of the decoded structure.
112
+ Field string
111
113
}
112
114
113
115
// NewMetricAggregation creates a new MetricAggregation of the specified type and field.
@@ -124,6 +126,27 @@ func NewMetricAggregation(metricType, field string) *MetricAggregation {
124
126
}
125
127
}
126
128
129
+ // PipelineAggregation represents a pipeline aggregation that processes the output of other aggregations.
130
+ type PipelineAggregation struct {
131
+ baseAggregation
132
+ Type string `mapstructure:"-"` // Type of pipeline: "derivative", "sum_bucket", etc. Not part of the decoded structure.
133
+ BucketsPath string
134
+ }
135
+
136
+ // NewPipelineAggregation creates a new PipelineAggregation of the specified type and buckets path.
137
+ func NewPipelineAggregation (pipelineType , bucketsPath string ) * PipelineAggregation {
138
+ switch pipelineType {
139
+ case MetricSumBucket :
140
+ // Valid pipeline types
141
+ default :
142
+ panic ("invalid pipeline type: " + pipelineType )
143
+ }
144
+ return & PipelineAggregation {
145
+ Type : pipelineType ,
146
+ BucketsPath : bucketsPath ,
147
+ }
148
+ }
149
+
127
150
// AddNested provides a correctly typed chained call for MetricAggregation.
128
151
func (a * MetricAggregation ) AddNested (name string , sub Aggregation ) Aggregation {
129
152
a .baseAggregation .AddNested (name , sub )
@@ -133,10 +156,11 @@ func (a *MetricAggregation) AddNested(name string, sub Aggregation) Aggregation
133
156
// DateHistogramAggregation represents bucketing documents by a date/time interval.
134
157
type DateHistogramAggregation struct {
135
158
baseAggregation
136
- Field string
137
- Interval string // A generic interval string like "1d", "1M", "1h".
138
- Format string
139
- TimeZone string
159
+ Field string
160
+ Interval string // A generic interval string like "1d", "1M", "1h".
161
+ Format string
162
+ TimeZone string
163
+ IntervalField string // es-specific field name for backward compatibility
140
164
}
141
165
142
166
// AddNested provides a correctly typed chained call for DateHistogramAggregation.
@@ -174,8 +198,23 @@ type FilterAggregation struct {
174
198
// Query holds the filter criteria for this aggregation.
175
199
Query map [string ]interface {} `json:"query"`
176
200
}
201
+
177
202
// AddNested provides a correctly typed chained call for FilterAggregation.
178
203
func (a * FilterAggregation ) AddNested (name string , sub Aggregation ) Aggregation {
179
204
a .baseAggregation .AddNested (name , sub )
180
205
return a
181
206
}
207
+
208
+ type DateRangeAggregation struct {
209
+ baseAggregation
210
+ Field string `json:"field"`
211
+ TimeZone string `json:"time_zone,omitempty"`
212
+ Format string `json:"format,omitempty"`
213
+ Ranges []interface {} `json:"ranges"`
214
+ }
215
+
216
+ // AddNested provides a correctly typed chained call for DateRangeAggregation.
217
+ func (a * DateRangeAggregation ) AddNested (name string , sub Aggregation ) Aggregation {
218
+ a .baseAggregation .AddNested (name , sub )
219
+ return a
220
+ }
0 commit comments