diff --git a/src/QueryGrammar.php b/src/QueryGrammar.php index 2e02106..8651e4e 100644 --- a/src/QueryGrammar.php +++ b/src/QueryGrammar.php @@ -802,9 +802,20 @@ protected function compileAggregation(Builder $builder, array $aggregation): arr $method = 'compile' . ucfirst(Str::camel($aggregation['type'])) . 'Aggregation'; - $compiled = [ - $key => $this->$method($aggregation) - ]; + if (method_exists($this, $method)) { + $compiled = [ + $key => $this->$method($aggregation) + ]; + } else { + $type = $aggregation['type']; + $args = $aggregation['args']; + + $compiled = [ + $key => [ + $type => $args, + ], + ]; + } if (isset($aggregation['aggregations']) && $aggregation['aggregations']->aggregations) { $compiled[$key]['aggregations'] = $this->compileAggregations($aggregation['aggregations']);