From 644fbd5519f6002401f9662b8631af1981049f91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mantas=20Jonu=C5=A1as?= <mantas.jonusas@nfq.lt>
Date: Tue, 21 Apr 2015 13:40:12 +0300
Subject: [PATCH] Added ParametersTrait in AbstractAgregation class

---
 Aggregation/AbstractAggregation.php | 10 +++++++++-
 Aggregation/TermsAggregation.php    |  4 +---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/Aggregation/AbstractAggregation.php b/Aggregation/AbstractAggregation.php
index 110a4a5..3dff51f 100644
--- a/Aggregation/AbstractAggregation.php
+++ b/Aggregation/AbstractAggregation.php
@@ -13,12 +13,15 @@ namespace ONGR\ElasticsearchBundle\DSL\Aggregation;
 
 use ONGR\ElasticsearchBundle\DSL\NamedBuilderBag;
 use ONGR\ElasticsearchBundle\DSL\NamedBuilderInterface;
+use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
 
 /**
  * AbstractAggregation class.
  */
 abstract class AbstractAggregation implements NamedBuilderInterface
 {
+    use ParametersTrait;
+
     const PREFIX = 'agg_';
 
     /**
@@ -113,7 +116,12 @@ abstract class AbstractAggregation implements NamedBuilderInterface
      */
     public function toArray()
     {
-        $result = [$this->getName() => [$this->getType() => $this->getArray()]];
+        $array = $this->getArray();
+        $result = [
+            $this->getName() => [
+                $this->getType() => is_array($array) ? $this->processArray($array) : $array,
+            ],
+        ];
 
         if ($this->supportsNesting()) {
             $nestedResult = $this->collectNestedAggregations();
diff --git a/Aggregation/TermsAggregation.php b/Aggregation/TermsAggregation.php
index 493189e..a12ec38 100644
--- a/Aggregation/TermsAggregation.php
+++ b/Aggregation/TermsAggregation.php
@@ -12,7 +12,6 @@
 namespace ONGR\ElasticsearchBundle\DSL\Aggregation;
 
 use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait;
-use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
 use ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait;
 
 /**
@@ -22,7 +21,6 @@ class TermsAggregation extends AbstractAggregation
 {
     use BucketingTrait;
     use ScriptAwareTrait;
-    use ParametersTrait;
 
     /**
      * {@inheritdoc}
@@ -44,6 +42,6 @@ class TermsAggregation extends AbstractAggregation
             ]
         );
 
-        return $this->processArray($data);
+        return $data;
     }
 }
-- 
GitLab