-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I'm trying to create a nested bucket aggregation using a callback in bucket(), but the nested aggregation never appears in the final DSL:
$regions = Enrollment::viaIndex()
->where('status', EnrollmentStatus::Studying)
->bucket(
'regions',
'terms',
['field' => 'student.region.id'],
fn (Builder $builder) => $builder->bucket('student_count', 'terms', ['field' => 'student.id'])
);
dd($regions->toSql());
Actual output:
"aggs": {
"regions": {
"terms": {
"field": "student.region.id",
"size": 1000
}
}
}
Expected output:
"aggs": {
"regions": {
"terms": { "field": "student.region.id" },
"aggs": {
"student_count": {
"terms": { "field": "student.id" }
}
}
}
}
Question
Is this the correct way to define nested bucket aggregations using a callback?
Or is there a different recommended approach for creating nested aggregations inside a bucket() call?
Thanks in advance!
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request