Files
opencloud/services/search/pkg/aggregation/aggregation_test.go
T
Dominik Schmidt 1c15b904d7 feat(search): add nested aggregations
Sub-aggregations on both engines: bleve folds child buckets below their parent through the same collector, OpenSearch nests them natively, so a request stays one search per space. The proto gains sub_aggregations on the option and on the bucket; merge, finalize, validation and the bucket limit walk every level, results are positional at every level, a metric has no buckets to nest in. AGG-10 to AGG-15, 20, 35, 40 and 44 in the parity suite, AGG-14 as a known OpenSearch divergence.
2026-11-27 15:51:35 +01:00

45 lines
1.7 KiB
Go

package aggregation_test
import (
"strconv"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
searchsvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/search/v0"
"github.com/opencloud-eu/opencloud/services/search/pkg/aggregation"
)
var _ = Describe("CheckBuckets", func() {
// artists of an album each: twice as many buckets as artists
artistsWithAlbum := func(artists int) []*searchsvc.AggregationResult {
res := &searchsvc.AggregationResult{Field: "audio.artist"}
for i := range artists {
res.Buckets = append(res.Buckets, &searchsvc.Bucket{Key: strconv.Itoa(i), Count: 1, SubAggregations: []*searchsvc.AggregationResult{
{Field: "audio.album", Buckets: []*searchsvc.Bucket{{Key: "Singles", Count: 1}}},
}})
}
return []*searchsvc.AggregationResult{res}
}
artists := func(count int) []*searchsvc.AggregationResult {
res := &searchsvc.AggregationResult{Field: "audio.artist"}
for i := range count {
res.Buckets = append(res.Buckets, &searchsvc.Bucket{Key: strconv.Itoa(i), Count: 1})
}
return []*searchsvc.AggregationResult{res}
}
It("counts the buckets against the limit, none is fine", func() {
Expect(aggregation.MaxBuckets).To(Equal(65535))
Expect(aggregation.CheckBuckets(nil)).To(Succeed())
Expect(aggregation.CheckBuckets(artists(65535))).To(Succeed())
Expect(aggregation.CheckBuckets(artists(65536))).To(MatchError(aggregation.ErrTooManyBuckets))
})
It("counts the buckets of all levels", func() {
Expect(aggregation.CheckBuckets(artistsWithAlbum(32767))).To(Succeed(), "65534 buckets")
Expect(aggregation.CheckBuckets(artistsWithAlbum(32768))).To(MatchError(aggregation.ErrTooManyBuckets), "65536 buckets")
})
})