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:
Gábor Farkas
2023-01-27 16:18:36 +01:00
committed by GitHub
parent d5433a488a
commit 88119ad6c3
9 changed files with 83 additions and 2 deletions

View File

@@ -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"`

View File

@@ -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{}),