diff --git a/src/Aggregation/Bucketing/DateRangeAggregation.php b/src/Aggregation/Bucketing/DateRangeAggregation.php
index 4de68cc7a26e959547f1bcf5a26b94ae9c967b0a..9b68dcb4a767a77cb60917217656b5a3d56b941e 100644
--- a/src/Aggregation/Bucketing/DateRangeAggregation.php
+++ b/src/Aggregation/Bucketing/DateRangeAggregation.php
@@ -74,7 +74,7 @@ class DateRangeAggregation extends AbstractAggregation
      * @param string|null $from
      * @param string|null $to
      *
-     * @return RangeAggregation
+     * @return $this
      *
      * @throws \LogicException
      */
diff --git a/tests/Unit/Aggregation/ChildrenAggregationTest.php b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php
similarity index 91%
rename from tests/Unit/Aggregation/ChildrenAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php
index dd5cd63757857b351ff76b66a2139a9621b39017..3e00acaef8f6596b0e8b8d6d6288cccb3d996088 100644
--- a/tests/Unit/Aggregation/ChildrenAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\ChildrenAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\ChildrenAggregation;
 
 /**
  * Unit test for children aggregation.
diff --git a/tests/Unit/Aggregation/DateHistogramAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php
similarity index 91%
rename from tests/Unit/Aggregation/DateHistogramAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php
index 5845f8867fd9e003824c631f0a59fc2d0e3336eb..da340c6d89baade4a4731702c12a5feb1524f507 100644
--- a/tests/Unit/Aggregation/DateHistogramAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\DateHistogramAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateHistogramAggregation;
 
 /**
  * Unit test for children aggregation.
diff --git a/tests/Unit/Aggregation/DateRangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php
similarity index 91%
rename from tests/Unit/Aggregation/DateRangeAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php
index 03afc285223cc722dae3f208b78fbc843ebebc35..8fc3bbbe3d4f11807385c7f1a1e4a0775db9677d 100644
--- a/tests/Unit/Aggregation/DateRangeAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\DateRangeAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateRangeAggregation;
 
 class DateRangeAggregationTest extends \PHPUnit_Framework_TestCase
 {
@@ -44,10 +44,9 @@ class DateRangeAggregationTest extends \PHPUnit_Framework_TestCase
      */
     public function testDateRangeAggregationGetArray()
     {
-        $agg = new DateRangeAggregation('foo');
+        $agg = new DateRangeAggregation('foo', 'baz');
         $agg->addRange(10, 20);
         $agg->setFormat('bar');
-        $agg->setField('baz');
         $result = $agg->getArray();
         $expected = [
             'format' => 'bar',
@@ -116,8 +115,10 @@ class DateRangeAggregationTest extends \PHPUnit_Framework_TestCase
     public function testDateRangeAggregationConstructor($field = null, $format = null, array $ranges = null)
     {
         /** @var DateRangeAggregation|\PHPUnit_Framework_MockObject_MockObject $aggregation */
-        $aggregation = $this->getMockBuilder('ONGR\ElasticsearchDSL\Aggregation\DateRangeAggregation')
-            ->disableOriginalConstructor()->getMock();
+        $aggregation = $this->getMockBuilder('ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateRangeAggregation')
+            ->setMethods(['setField', 'setFormat', 'addRange'])
+            ->disableOriginalConstructor()
+            ->getMock();
         $aggregation->expects($this->once())->method('setField')->with($field);
         $aggregation->expects($this->once())->method('setFormat')->with($format);
         $aggregation->expects($this->exactly(count($ranges)))->method('addRange');
diff --git a/tests/Unit/Aggregation/FilterAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php
similarity index 94%
rename from tests/Unit/Aggregation/FilterAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php
index 9386df2395b72a2efe54f18b2aa5d4625e14b791..a067b94546004a3dc0122fc3ebca9e5c4c3aac66 100644
--- a/tests/Unit/Aggregation/FilterAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php
@@ -9,10 +9,10 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\FilterAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\HistogramAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FilterAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\HistogramAggregation;
 use ONGR\ElasticsearchDSL\Query\BoolQuery;
 use ONGR\ElasticsearchDSL\Query\ExistsQuery;
 use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
diff --git a/tests/Unit/Aggregation/FiltersAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php
similarity index 96%
rename from tests/Unit/Aggregation/FiltersAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php
index b487fd9ced6070fa132c535363e672c91f560172..f5b4369daf75ffa06ea03c0e24371e2c374fb3a3 100644
--- a/tests/Unit/Aggregation/FiltersAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\FiltersAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FiltersAggregation;
 use ONGR\ElasticsearchDSL\BuilderInterface;
 
 /**
diff --git a/tests/Unit/Aggregation/GeoDistanceAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php
similarity index 96%
rename from tests/Unit/Aggregation/GeoDistanceAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php
index 1c5d21b68586e8691f830722f22a28734ded2fd9..c19b1f1318c8fe7c117c26f66c3505d211d480d5 100644
--- a/tests/Unit/Aggregation/GeoDistanceAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\GeoDistanceAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GeoDistanceAggregation;
 
 class GeoDistanceAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/GeoHashGridAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php
similarity index 93%
rename from tests/Unit/Aggregation/GeoHashGridAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php
index 499d642d6d44e67308ccda4126412a0a7805274a..627a4f316262ac61284350fc4edd4bd28825019b 100644
--- a/tests/Unit/Aggregation/GeoHashGridAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\GeoHashGridAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GeoHashGridAggregation;
 
 /**
  * Unit test for geohash grid aggregation.
diff --git a/tests/Unit/Aggregation/GlobalAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php
similarity index 93%
rename from tests/Unit/Aggregation/GlobalAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php
index 40e101e5d298e4f1fcd9de424af49ac665e62da5..03f5ca9092e70c926a18eacfc82f0c39139b354c 100644
--- a/tests/Unit/Aggregation/GlobalAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\GlobalAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GlobalAggregation;
 
 class GlobalAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/Ipv4RangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php
similarity index 89%
rename from tests/Unit/Aggregation/Ipv4RangeAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php
index 4d42c4143a0385f9cdbe068604160eafd39b2a93..f6b60db4145f594346ec72b7276e3e7b08bc4252 100644
--- a/tests/Unit/Aggregation/Ipv4RangeAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php
@@ -9,10 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\Ipv4RangeAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\Ipv4RangeAggregation;
 
 class Ipv4RangeAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/MissingAggregationTest.php b/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php
similarity index 89%
rename from tests/Unit/Aggregation/MissingAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php
index ed8d222cde0c7b88aa7338c09c27536273611e81..11f6b4ab09fa926da5f70b307896d7fdefd315e4 100644
--- a/tests/Unit/Aggregation/MissingAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\MissingAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\MissingAggregation;
 
 class MissingAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/NestedAggregationTest.php b/tests/Unit/Aggregation/Bucketing/NestedAggregationTest.php
similarity index 82%
rename from tests/Unit/Aggregation/NestedAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/NestedAggregationTest.php
index f24a00277f4ec56bbd28f5688718b185108f6d2b..51886af59cfa2d8fe8d3849dc37274889bb6d7fb 100644
--- a/tests/Unit/Aggregation/NestedAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/NestedAggregationTest.php
@@ -9,10 +9,10 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\NestedAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\NestedAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation;
 
 class NestedAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/RangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php
similarity index 97%
rename from tests/Unit/Aggregation/RangeAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php
index 70ee5cca3e7f59a08d3fb2da8a843b9561f42dbe..741a0be9cdb33841019ee29860dc6253f6ff1aa0 100644
--- a/tests/Unit/Aggregation/RangeAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php
@@ -9,10 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\RangeAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\RangeAggregation;
 
 class RangeAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/ReverseNestedAggregationTest.php b/tests/Unit/Aggregation/Bucketing/ReverseNestedAggregationTest.php
similarity index 87%
rename from tests/Unit/Aggregation/ReverseNestedAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/ReverseNestedAggregationTest.php
index 2c12f60a621a047e755eaffbc129748b1aa5108c..e14a055f83ed6e6bc9a90da37207cf4a9c5894dd 100644
--- a/tests/Unit/Aggregation/ReverseNestedAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/ReverseNestedAggregationTest.php
@@ -9,11 +9,10 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\ReverseNestedAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\ReverseNestedAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation;
 
 class ReverseNestedAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/SamplerAggregationTest.php b/tests/Unit/Aggregation/Bucketing/SamplerAggregationTest.php
similarity index 88%
rename from tests/Unit/Aggregation/SamplerAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/SamplerAggregationTest.php
index 4ac64c8bbfae4c7f2e3fa001199cd7aa1ffa1547..09a945561bd9992e4cf9dd91ae64bd6c7847f2fb 100644
--- a/tests/Unit/Aggregation/SamplerAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/SamplerAggregationTest.php
@@ -9,10 +9,10 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\SamplerAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\SamplerAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation;
 
 /**
  * Unit test for children aggregation.
diff --git a/tests/Unit/Aggregation/SignificantTermsAggregationTest.php b/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php
similarity index 89%
rename from tests/Unit/Aggregation/SignificantTermsAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php
index 6f75c1be7dded42100550101be222a8013a98ac1..98da346fcfbece632ae47dd778324cb72aaf3114 100644
--- a/tests/Unit/Aggregation/SignificantTermsAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\SignificantTermsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\SignificantTermsAggregation;
 
 /**
  * Unit test for children aggregation.
diff --git a/tests/Unit/Aggregation/TermsAggregationTest.php b/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php
similarity index 96%
rename from tests/Unit/Aggregation/TermsAggregationTest.php
rename to tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php
index 3d61d8f6084ea5eea529dee3a76575bee08f26ee..ea9c826799d31a82ff7431fb83b0d59e284892a3 100644
--- a/tests/Unit/Aggregation/TermsAggregationTest.php
+++ b/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php
@@ -9,10 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation;
 
 class TermsAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/CardinalityAggregationTest.php b/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php
similarity index 94%
rename from tests/Unit/Aggregation/CardinalityAggregationTest.php
rename to tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php
index 4cf5d1d23017bccc10a3c285791d85b295fa2a90..14cf1b0863da9b56a3ecf99003864b5e38916318 100644
--- a/tests/Unit/Aggregation/CardinalityAggregationTest.php
+++ b/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\CardinalityAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Metric\CardinalityAggregation;
 
 /**
  * Unit test for cardinality aggregation.
diff --git a/tests/Unit/Aggregation/GeoBoundsAggregationTest.php b/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php
similarity index 90%
rename from tests/Unit/Aggregation/GeoBoundsAggregationTest.php
rename to tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php
index 505b9125029374baff6be691effabee8e345f501..02984bf4dd047c108d2e9770037c0edecb9fc3bf 100644
--- a/tests/Unit/Aggregation/GeoBoundsAggregationTest.php
+++ b/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php
@@ -9,10 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\GeoBoundsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Metric\GeoBoundsAggregation;
 
 /**
  * Unit test for geo bounds aggregation.
diff --git a/tests/Unit/Aggregation/GeoCentroidAggregationTest.php b/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php
similarity index 89%
rename from tests/Unit/Aggregation/GeoCentroidAggregationTest.php
rename to tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php
index a28a16ce72384bbfc93e5743028ca037e02e4a15..4f263e547ac0d2e5f9cdb5716b13758677b6ee11 100644
--- a/tests/Unit/Aggregation/GeoCentroidAggregationTest.php
+++ b/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\GeoCentroidAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Metric\GeoCentroidAggregation;
 
 /**
  * Unit test for children aggregation.
diff --git a/tests/Unit/Aggregation/PercentileRanksAggregationTest.php b/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php
similarity index 91%
rename from tests/Unit/Aggregation/PercentileRanksAggregationTest.php
rename to tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php
index 8c71bbd16e3ac59fb7fc755f63d13d0365fb367d..dd3ae46b2eaa0ae1e0632ae3cb9f8aaaba5fb36f 100644
--- a/tests/Unit/Aggregation/PercentileRanksAggregationTest.php
+++ b/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php
@@ -9,10 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\PercentileRanksAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Metric\PercentileRanksAggregation;
 
 /**
  * Percentile ranks aggregation unit tests.
diff --git a/tests/Unit/Aggregation/PercentilesAggregationTest.php b/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php
similarity index 90%
rename from tests/Unit/Aggregation/PercentilesAggregationTest.php
rename to tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php
index a7c4fff44626429a9813e73a18d0f7764cdc1265..b7cbec25aace6d2ae1b0f0271f310926b3a864de 100644
--- a/tests/Unit/Aggregation/PercentilesAggregationTest.php
+++ b/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\PercentilesAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Metric\PercentilesAggregation;
 
 class PercentilesAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/StatsAggregationTest.php b/tests/Unit/Aggregation/Metric/StatsAggregationTest.php
similarity index 86%
rename from tests/Unit/Aggregation/StatsAggregationTest.php
rename to tests/Unit/Aggregation/Metric/StatsAggregationTest.php
index 4d98696984592f8c5c6f8029c60a9bb22f39aa28..794bb80ccdeeaf9d02690925b91dfea658dbe1ac 100644
--- a/tests/Unit/Aggregation/StatsAggregationTest.php
+++ b/tests/Unit/Aggregation/Metric/StatsAggregationTest.php
@@ -9,10 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\StatsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Metric\StatsAggregation;
 
 class StatsAggregationTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/Unit/Aggregation/TopHitsAggregationTest.php b/tests/Unit/Aggregation/Metric/TopHitsAggregationTest.php
similarity index 92%
rename from tests/Unit/Aggregation/TopHitsAggregationTest.php
rename to tests/Unit/Aggregation/Metric/TopHitsAggregationTest.php
index 127e02b5a0ffa854837f415bd6f696b1b8ad72bc..53f6294effd83bde01113b423ea375642df097f9 100644
--- a/tests/Unit/Aggregation/TopHitsAggregationTest.php
+++ b/tests/Unit/Aggregation/Metric/TopHitsAggregationTest.php
@@ -9,9 +9,9 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation;
 
-use ONGR\ElasticsearchDSL\Aggregation\TopHitsAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Metric\TopHitsAggregation;
 use ONGR\ElasticsearchDSL\Sort\FieldSort;
 
 /**
diff --git a/tests/Unit/Integration/SearchTest.php b/tests/Unit/Integration/SearchTest.php
deleted file mode 100644
index fb2c6e366f0eb06dfc6f41665fc5b082a9450af5..0000000000000000000000000000000000000000
--- a/tests/Unit/Integration/SearchTest.php
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-
-/*
- * This file is part of the ONGR package.
- *
- * (c) NFQ Technologies UAB <info@nfq.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Integration;
-
-use ONGR\ElasticsearchDSL\Aggregation\FiltersAggregation;
-use ONGR\ElasticsearchDSL\Aggregation\HistogramAggregation;
-use ONGR\ElasticsearchDSL\Query\TermQuery;
-use ONGR\ElasticsearchDSL\Search;
-use PHPUnit_Framework_TestCase;
-
-/**
- * Tests integration of examples from the documentation.
- */
-class SearchTest extends PHPUnit_Framework_TestCase
-{
-    /**
-     * Tests integration of the FiltersAggregation named example from the documentation.
-     *
-     * @link https://github.com/ongr-io/ElasticsearchDSL/blob/master/docs/Aggregation/Filters.md#named-example
-     */
-    public function testFiltersAggregationNamedExample()
-    {
-        $errorTermFilter = new TermQuery('body', 'error');
-        $warningTermFilter = new TermQuery('body', 'warning');
-
-        $histogramAggregation = new HistogramAggregation('monthly', 'timestamp');
-        $histogramAggregation->setInterval('1M');
-
-        $filterAggregation = new FiltersAggregation(
-            'grades_stats',
-            [
-                'error' => $errorTermFilter,
-                'warning' => $warningTermFilter,
-            ]
-        );
-        $filterAggregation->addAggregation($histogramAggregation);
-
-        $search = new Search();
-        $search->addAggregation($filterAggregation);
-
-        $this->assertSame(
-            [
-                'aggregations' => [
-                    'grades_stats' => [
-                        'filters' => [
-                            'filters' => [
-                                'error' => [
-                                    'term' => [
-                                        'body' => 'error',
-                                    ],
-                                ],
-                                'warning' => [
-                                    'term' => [
-                                        'body' => 'warning',
-                                    ],
-                                ],
-                            ],
-                        ],
-                        'aggregations' => [
-                            'monthly' => [
-                                'histogram' => [
-                                    'field' => 'timestamp',
-                                    'interval' => '1M',
-                                ],
-                            ],
-                        ],
-                    ],
-                ],
-            ],
-            $search->toArray()
-        );
-    }
-
-    /**
-     * Tests integration of the FiltersAggregation anonymous example from the documentation.
-     *
-     * @link https://github.com/ongr-io/ElasticsearchDSL/blob/master/docs/Aggregation/Filters.md#anonymous-example
-     */
-    public function testFiltersAggregationAnonymousExample()
-    {
-        $errorTermFilter = new TermQuery('body', 'error');
-        $warningTermFilter = new TermQuery('body', 'warning');
-
-        $histogramAggregation = new HistogramAggregation('monthly', 'timestamp');
-        $histogramAggregation->setInterval('1M');
-
-        $filterAggregation = new FiltersAggregation(
-            'grades_stats',
-            [
-                'error' => $errorTermFilter,
-                'warning' => $warningTermFilter,
-            ],
-            true
-        );
-        $filterAggregation->addAggregation($histogramAggregation);
-
-        $search = new Search();
-        $search->addAggregation($filterAggregation);
-
-        $this->assertSame(
-            [
-                'aggregations' => [
-                    'grades_stats' => [
-                        'filters' => [
-                            'filters' => [
-                                [
-                                    'term' => [
-                                        'body' => 'error',
-                                    ],
-                                ],
-                                [
-                                    'term' => [
-                                        'body' => 'warning',
-                                    ],
-                                ],
-                            ],
-                        ],
-                        'aggregations' => [
-                            'monthly' => [
-                                'histogram' => [
-                                    'field' => 'timestamp',
-                                    'interval' => '1M',
-                                ],
-                            ],
-                        ],
-                    ],
-                ],
-            ],
-            $search->toArray()
-        );
-    }
-}
diff --git a/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php b/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php
index a61dba8a573529a1cdbd97909f6f266d3b158434..d08a33425530fd8baabdef8adcdff97f0b6fdbaf 100644
--- a/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php
+++ b/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php
@@ -11,7 +11,7 @@
 
 namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint;
 
-use ONGR\ElasticsearchDSL\Aggregation\MissingAggregation;
+use ONGR\ElasticsearchDSL\Aggregation\Bucketing\MissingAggregation;
 use ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint;
 
 /**
diff --git a/tests/Unit/SearchEndpoint/SuggestEndpointTest.php b/tests/Unit/SearchEndpoint/SuggestEndpointTest.php
index e6e1cca3705a54ef9c8bcc4f0a78bb9b48ce9c20..f71884f4ad158b5b677eef54b282a14489cce228 100644
--- a/tests/Unit/SearchEndpoint/SuggestEndpointTest.php
+++ b/tests/Unit/SearchEndpoint/SuggestEndpointTest.php
@@ -12,7 +12,7 @@
 namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint;
 
 use ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint;
-use ONGR\ElasticsearchDSL\Suggest\TermSuggest;
+use ONGR\ElasticsearchDSL\Suggest\Suggest;
 use PHPUnit_Framework_MockObject_MockObject as MockObject;
 use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
 
@@ -33,7 +33,7 @@ class SuggestEndpointTest extends \PHPUnit_Framework_TestCase
     {
         $suggestName = 'acme_suggest';
         $text = 'foo';
-        $suggest = new TermSuggest($suggestName, $text);
+        $suggest = new Suggest($suggestName, 'text', $text, 'acme');
         $endpoint = new SuggestEndpoint();
         $endpoint->add($suggest, $suggestName);
         $builders = $endpoint->getAll();
@@ -54,7 +54,7 @@ class SuggestEndpointTest extends \PHPUnit_Framework_TestCase
             'Symfony\Component\Serializer\Normalizer\NormalizerInterface'
         );
 
-        $suggest = new TermSuggest('foo', 'bar');
+        $suggest = new Suggest('foo', 'bar', 'acme', 'foo');
         $instance->add($suggest);
 
         $this->assertEquals(
diff --git a/tests/Unit/SearchTest.php b/tests/Unit/SearchTest.php
index aca65444706f55dbb144f48e5d5b7958fc0da171..a6c9db1cd9e9fa53198b2d08f6fcdd3872f8e5a7 100644
--- a/tests/Unit/SearchTest.php
+++ b/tests/Unit/SearchTest.php
@@ -15,7 +15,7 @@ use ONGR\ElasticsearchDSL\Query\ExistsQuery;
 use ONGR\ElasticsearchDSL\Query\TermQuery;
 use ONGR\ElasticsearchDSL\Search;
 use ONGR\ElasticsearchDSL\Sort\FieldSort;
-use ONGR\ElasticsearchDSL\Suggest\TermSuggest;
+use ONGR\ElasticsearchDSL\Suggest\Suggest;
 
 /**
  * Test for Search.
@@ -266,7 +266,7 @@ class SearchTest extends \PHPUnit_Framework_TestCase
                     ],
                 ],
             ],
-            (new Search())->addSuggest(new TermSuggest('foo', 'bar', ['field' => 'title', 'size' => 2])),
+            (new Search())->addSuggest(new Suggest('foo', 'term', 'bar', 'title', ['size' => 2])),
         ];
 
         $cases['multiple_suggests'] = [
@@ -283,8 +283,8 @@ class SearchTest extends \PHPUnit_Framework_TestCase
                 ],
             ],
             (new Search())
-                ->addSuggest(new TermSuggest('foo', 'bar', ['field' => 'title', 'size' => 2]))
-                ->addSuggest(new TermSuggest('bar', 'foo', ['field' => 'title', 'size' => 2])),
+                ->addSuggest(new Suggest('foo', 'term', 'bar', 'title', ['size' => 2]))
+                ->addSuggest(new Suggest('bar', 'term', 'foo', 'title', ['size' => 2])),
         ];
 
         return $cases;
diff --git a/tests/Unit/Suggest/CompletionSuggestTest.php b/tests/Unit/Suggest/CompletionSuggestTest.php
deleted file mode 100644
index 066ae5b8adebeb6163f1927ea5d02f166e5c8a58..0000000000000000000000000000000000000000
--- a/tests/Unit/Suggest/CompletionSuggestTest.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-
-/*
- * This file is part of the ONGR package.
- *
- * (c) NFQ Technologies UAB <info@nfq.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Suggest;
-
-use ONGR\ElasticsearchDSL\Suggest\CompletionSuggest;
-
-class CompletionSuggestTest extends \PHPUnit_Framework_TestCase
-{
-    /**
-     * Tests getType method.
-     */
-    public function testSuggestGetType()
-    {
-        $suggest = new CompletionSuggest('foo', 'bar');
-        $result = $suggest->getType();
-        $this->assertEquals('completion_suggest', $result);
-    }
-
-    /**
-     * Tests toArray() method.
-     */
-    public function testSuggestWithoutFieldAndSize()
-    {
-        // Case #1 suggest without field and size params.
-        $suggest = new CompletionSuggest('foo', 'bar');
-        $expected = ['foo' => [
-            'text' => 'bar',
-            'completion' => [
-                'field' => 'suggest',
-                'size' => 3,
-            ],
-        ]];
-        $this->assertEquals($expected, $suggest->toArray());
-    }
-
-    /**
-     * Tests toArray() method.
-     */
-    public function testToArray()
-    {
-        $suggest = new CompletionSuggest(
-            'foo',
-            'bar',
-            [
-                'size' => 5,
-                'field' => 'title',
-                'fuzzy' => ['fuzziness' => 2]
-            ]
-        );
-        $expected = ['foo' => [
-            'text' => 'bar',
-            'completion' => [
-                'field' => 'title',
-                'size' => 5,
-                'fuzzy' => ['fuzziness' => 2]
-            ],
-        ]];
-        $this->assertEquals($expected, $suggest->toArray());
-    }
-
-    public function testToArrayWithoutField()
-    {
-        $suggest = new CompletionSuggest(
-            'foo',
-            'bar',
-            [
-                'size' => 5,
-                'fuzzy' => ['fuzziness' => 2]
-            ]
-        );
-        $expected = ['foo' => [
-            'text' => 'bar',
-            'completion' => [
-                'field' => 'suggest',
-                'size' => 5,
-                'fuzzy' => ['fuzziness' => 2]
-            ],
-        ]];
-        $this->assertEquals($expected, $suggest->toArray());
-    }
-}
diff --git a/tests/Unit/Suggest/TermSuggestTest.php b/tests/Unit/Suggest/TermSuggestTest.php
deleted file mode 100644
index 6492937d52d9c2172bc803be13570a0958e6183b..0000000000000000000000000000000000000000
--- a/tests/Unit/Suggest/TermSuggestTest.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-/*
- * This file is part of the ONGR package.
- *
- * (c) NFQ Technologies UAB <info@nfq.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace ONGR\ElasticsearchDSL\Tests\Unit\Suggest;
-
-use ONGR\ElasticsearchDSL\Suggest\TermSuggest;
-
-class TermSuggestTest extends \PHPUnit_Framework_TestCase
-{
-    /**
-     * Tests getType method.
-     */
-    public function testSuggestGetType()
-    {
-        $suggest = new TermSuggest('foo', 'bar');
-        $result = $suggest->getType();
-        $this->assertEquals('term_suggest', $result);
-    }
-
-    /**
-     * Tests toArray() method.
-     */
-    public function testSuggestWithoutFieldAndSize()
-    {
-        // Case #1 suggest without field and size params.
-        $suggest = new TermSuggest('foo', 'bar');
-        $expected = ['foo' => [
-            'text' => 'bar',
-            'term' => [
-                'field' => '_all',
-                'size' => 3,
-            ],
-        ]];
-        $this->assertEquals($expected, $suggest->toArray());
-    }
-
-    /**
-     * Tests toArray() method.
-     */
-    public function testToArray()
-    {
-        $suggest = new TermSuggest(
-            'foo',
-            'bar',
-            [
-                'size' => 5,
-                'field' => 'title',
-                'analyzer' => 'whitespace',
-            ]
-        );
-        $expected = ['foo' => [
-            'text' => 'bar',
-            'term' => [
-                'field' => 'title',
-                'size' => 5,
-                'analyzer' => 'whitespace',
-            ],
-        ]];
-        $this->assertEquals($expected, $suggest->toArray());
-    }
-}