diff --git a/Aggregation/StatsAggregation.php b/Aggregation/StatsAggregation.php index 73c305218d8e30fad2613a3181d18c77d1dc992b..4952837431f10725d6f31dd6e60a1783b863dfdf 100644 --- a/Aggregation/StatsAggregation.php +++ b/Aggregation/StatsAggregation.php @@ -12,6 +12,7 @@ namespace ONGR\ElasticsearchBundle\DSL\Aggregation; use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\MetricTrait; +use ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait; /** * Class representing StatsAggregation. @@ -19,6 +20,7 @@ use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\MetricTrait; class StatsAggregation extends AbstractAggregation { use MetricTrait; + use ScriptAwareTrait; /** * {@inheritdoc} @@ -33,6 +35,14 @@ class StatsAggregation extends AbstractAggregation */ public function getArray() { - return $this->getField() ? ['field' => $this->getField()] : new \stdClass(); + $out = []; + if ($this->getField()) { + $out['field'] = $this->getField(); + } + if ($this->getScript()) { + $out['script'] = $this->getScript(); + } + + return $out; } }