From fc4709cc9d828917648d63e5d48bc6c2934957d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mantas=20Jonu=C5=A1as?= <mantas.jonusas@nfq.lt>
Date: Tue, 24 Mar 2015 09:54:43 +0200
Subject: [PATCH] Stats aggregation now accepts scripts

---
 Aggregation/StatsAggregation.php | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Aggregation/StatsAggregation.php b/Aggregation/StatsAggregation.php
index 73c3052..4952837 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;
     }
 }
-- 
GitLab