mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Support nested aggregation (#62301)
* Add nested query support * Add nested support for alerts * update nested aggregation * cleanup types * Add nested integration test * Move aggdef to nested * fixed merge conflict * fixed lint warning * mark nested-mode experimental --------- Co-authored-by: Ethan Gallant <ethan@ziax.com> Co-authored-by: Ethan J. Gallant <ethan.gallant@acquia.com>
This commit is contained in:
@@ -236,6 +236,11 @@ type TermsAggregation struct {
|
||||
Missing *string `json:"missing,omitempty"`
|
||||
}
|
||||
|
||||
// NestedAggregation represents a nested aggregation
|
||||
type NestedAggregation struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
// ExtendedBounds represents extended bounds
|
||||
type ExtendedBounds struct {
|
||||
Min int64 `json:"min"`
|
||||
|
||||
@@ -270,6 +270,7 @@ type AggBuilder interface {
|
||||
Histogram(key, field string, fn func(a *HistogramAgg, b AggBuilder)) AggBuilder
|
||||
DateHistogram(key, field string, fn func(a *DateHistogramAgg, b AggBuilder)) AggBuilder
|
||||
Terms(key, field string, fn func(a *TermsAggregation, b AggBuilder)) AggBuilder
|
||||
Nested(key, path string, fn func(a *NestedAggregation, b AggBuilder)) AggBuilder
|
||||
Filters(key string, fn func(a *FiltersAggregation, b AggBuilder)) AggBuilder
|
||||
GeoHashGrid(key, field string, fn func(a *GeoHashGridAggregation, b AggBuilder)) AggBuilder
|
||||
Metric(key, metricType, field string, fn func(a *MetricAggregation)) AggBuilder
|
||||
@@ -382,6 +383,26 @@ func (b *aggBuilderImpl) Terms(key, field string, fn func(a *TermsAggregation, b
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *aggBuilderImpl) Nested(key, field string, fn func(a *NestedAggregation, b AggBuilder)) AggBuilder {
|
||||
innerAgg := &NestedAggregation{
|
||||
Path: field,
|
||||
}
|
||||
aggDef := newAggDef(key, &aggContainer{
|
||||
Type: "nested",
|
||||
Aggregation: innerAgg,
|
||||
})
|
||||
|
||||
if fn != nil {
|
||||
builder := newAggBuilder()
|
||||
aggDef.builders = append(aggDef.builders, builder)
|
||||
fn(innerAgg, builder)
|
||||
}
|
||||
|
||||
b.aggDefs = append(b.aggDefs, aggDef)
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *aggBuilderImpl) Filters(key string, fn func(a *FiltersAggregation, b AggBuilder)) AggBuilder {
|
||||
innerAgg := &FiltersAggregation{
|
||||
Filters: make(map[string]interface{}),
|
||||
|
||||
Reference in New Issue
Block a user