From b5036a556a814d51ed9047aef4ba5e5080e36e73 Mon Sep 17 00:00:00 2001 From: Will Taylor-Jackson Date: Wed, 28 Feb 2024 08:54:29 +0000 Subject: [PATCH] feat: support general aggregations without method --- src/QueryGrammar.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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']);