From 30fb9aef170bceb05d6a29ddfcbc70bc72bbda70 Mon Sep 17 00:00:00 2001
From: Mantas Varatiejus <mantas.varatiejus@nfq.com>
Date: Mon, 21 Dec 2015 13:46:16 +0200
Subject: [PATCH] Deprecate filters

---
 docs/Filter/Or.md                         |   2 +
 src/Filter/AndFilter.php                  |   7 ++
 src/Filter/BoolFilter.php                 |   7 ++
 src/Filter/ExistsFilter.php               |  41 ++-------
 src/Filter/GeoBoundingBoxFilter.php       |  73 ++--------------
 src/Filter/GeoDistanceFilter.php          |  65 ++------------
 src/Filter/GeoDistanceRangeFilter.php     |  62 ++-----------
 src/Filter/GeoPolygonFilter.php           |  55 ++----------
 src/Filter/GeoShapeFilter.php             |  90 ++-----------------
 src/Filter/GeohashCellFilter.php          |  56 ++----------
 src/Filter/HasChildFilter.php             |  51 ++++-------
 src/Filter/HasParentFilter.php            |  53 ++++-------
 src/Filter/IdsFilter.php                  |  49 ++---------
 src/Filter/IndicesFilter.php              |   7 ++
 src/Filter/LimitFilter.php                |  41 ++-------
 src/Filter/MatchAllFilter.php             |  26 ++----
 src/Filter/MissingFilter.php              |  49 ++---------
 src/Filter/NestedFilter.php               |  57 +++---------
 src/Filter/NotFilter.php                  |   7 ++
 src/Filter/OrFilter.php                   |   7 ++
 src/Filter/PrefixFilter.php               |  44 ++--------
 src/Filter/QueryFilter.php                |   7 ++
 src/Filter/RangeFilter.php                |  48 +++-------
 src/Filter/RegexpFilter.php               |   7 ++
 src/Filter/ScriptFilter.php               |   7 ++
 src/Filter/TermFilter.php                 |  35 ++++----
 src/Filter/TermsFilter.php                |  55 ++----------
 src/Filter/TypeFilter.php                 |  43 ++-------
 src/Query/ExistsQuery.php                 |  55 ++++++++++++
 src/Query/FilteredQuery.php               |   8 ++
 src/Query/GeoBoundingBoxQuery.php         |  85 ++++++++++++++++++
 src/Query/GeoDistanceQuery.php            |  77 ++++++++++++++++
 src/Query/GeoDistanceRangeQuery.php       |  74 ++++++++++++++++
 src/Query/GeoPolygonQuery.php             |  66 ++++++++++++++
 src/Query/GeoShapeQuery.php               | 102 ++++++++++++++++++++++
 src/Query/GeohashCellQuery.php            |  67 ++++++++++++++
 src/Query/HasChildQuery.php               |   4 +-
 src/Query/HasParentQuery.php              |   4 +-
 src/Query/IdsQuery.php                    |   4 +-
 src/Query/IndicesQuery.php                |   4 +-
 src/Query/LimitQuery.php                  |  53 +++++++++++
 src/Query/MatchAllQuery.php               |   4 +-
 src/Query/MissingQuery.php                |  61 +++++++++++++
 src/Query/NestedQuery.php                 |   8 +-
 src/Query/PrefixQuery.php                 |  39 ++++++++-
 src/Query/RegexpQuery.php                 |   4 +-
 src/Query/ScriptQuery.php                 |  59 +++++++++++++
 src/Query/TermQuery.php                   |   4 +-
 src/Query/TermsQuery.php                  |  20 +++--
 src/Query/TypeQuery.php                   |  55 ++++++++++++
 tests/Filter/RangeFilterTest.php          |   9 +-
 tests/Query/ExistsQueryTest.php           |  29 ++++++
 tests/Query/GeoBoundingBoxQueryTest.php   |  87 ++++++++++++++++++
 tests/Query/GeoDistanceQueryTest.php      |  62 +++++++++++++
 tests/Query/GeoDistanceRangeQueryTest.php |  62 +++++++++++++
 tests/Query/GeoPolygonQueryTest.php       |  88 +++++++++++++++++++
 tests/Query/GeoShapeQueryTest.php         |  61 +++++++++++++
 tests/Query/GeohashCellQueryTest.php      |  59 +++++++++++++
 tests/Query/LimitQueryTest.php            |  27 ++++++
 tests/Query/MissingQueryTest.php          |  48 ++++++++++
 tests/Query/NestedQueryTest.php           |  67 +++++++-------
 tests/Query/ScriptQueryTest.php           |  54 ++++++++++++
 tests/Query/TypeQueryTest.php             |  27 ++++++
 63 files changed, 1743 insertions(+), 845 deletions(-)
 create mode 100644 src/Query/ExistsQuery.php
 create mode 100644 src/Query/GeoBoundingBoxQuery.php
 create mode 100644 src/Query/GeoDistanceQuery.php
 create mode 100644 src/Query/GeoDistanceRangeQuery.php
 create mode 100644 src/Query/GeoPolygonQuery.php
 create mode 100644 src/Query/GeoShapeQuery.php
 create mode 100644 src/Query/GeohashCellQuery.php
 create mode 100644 src/Query/LimitQuery.php
 create mode 100644 src/Query/MissingQuery.php
 create mode 100644 src/Query/ScriptQuery.php
 create mode 100644 src/Query/TypeQuery.php
 create mode 100644 tests/Query/ExistsQueryTest.php
 create mode 100644 tests/Query/GeoBoundingBoxQueryTest.php
 create mode 100644 tests/Query/GeoDistanceQueryTest.php
 create mode 100644 tests/Query/GeoDistanceRangeQueryTest.php
 create mode 100644 tests/Query/GeoPolygonQueryTest.php
 create mode 100644 tests/Query/GeoShapeQueryTest.php
 create mode 100644 tests/Query/GeohashCellQueryTest.php
 create mode 100644 tests/Query/LimitQueryTest.php
 create mode 100644 tests/Query/MissingQueryTest.php
 create mode 100644 tests/Query/ScriptQueryTest.php
 create mode 100644 tests/Query/TypeQueryTest.php

diff --git a/docs/Filter/Or.md b/docs/Filter/Or.md
index 7c8ef3c..34a666a 100644
--- a/docs/Filter/Or.md
+++ b/docs/Filter/Or.md
@@ -1,5 +1,7 @@
 # Or Filter
 
+__DEPRECATED:__ `OrFilter` is deprecated and will be removed in 2.0. Use `BoolQuery` instead.
+
 > More info about or filter is in the [official elasticsearch docs][1]
 
 A filter that matches documents using the OR boolean operator on other filters.
diff --git a/src/Filter/AndFilter.php b/src/Filter/AndFilter.php
index 7c4ac59..3be326c 100644
--- a/src/Filter/AndFilter.php
+++ b/src/Filter/AndFilter.php
@@ -11,6 +11,11 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The AndFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
@@ -18,6 +23,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
  * Represents Elasticsearch "and" filter.
  *
  * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html
+ *
+ * @deprecated Will be removed in 2.0. Use the BoolQuery instead.
  */
 class AndFilter implements BuilderInterface
 {
diff --git a/src/Filter/BoolFilter.php b/src/Filter/BoolFilter.php
index caf079b..a3699a0 100644
--- a/src/Filter/BoolFilter.php
+++ b/src/Filter/BoolFilter.php
@@ -11,12 +11,19 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The BoolFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\Query\BoolQuery;
 
 /**
  * Represents Elasticsearch "bool" filter.
  *
  * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
+ *
+ * @deprecated Will be removed in 2.0. Use the BoolQuery instead.
  */
 class BoolFilter extends BoolQuery
 {
diff --git a/src/Filter/ExistsFilter.php b/src/Filter/ExistsFilter.php
index 2c60b13..31f4894 100644
--- a/src/Filter/ExistsFilter.php
+++ b/src/Filter/ExistsFilter.php
@@ -11,43 +11,20 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
+@trigger_error(
+    'The ExistsFilter class is deprecated and will be removed in 2.0. Use ExistsQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\ExistsQuery;
 
 /**
  * Represents Elasticsearch "exists" filter.
  *
  * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html
+ *
+ * @deprecated Will be removed in 2.0. Use the ExistsQuery instead.
  */
-class ExistsFilter implements BuilderInterface
+class ExistsFilter extends ExistsQuery
 {
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @param string $field Field value.
-     */
-    public function __construct($field)
-    {
-        $this->field = $field;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'exists';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        return [
-            'field' => $this->field,
-        ];
-    }
 }
diff --git a/src/Filter/GeoBoundingBoxFilter.php b/src/Filter/GeoBoundingBoxFilter.php
index 22fb5a3..1aacf8b 100644
--- a/src/Filter/GeoBoundingBoxFilter.php
+++ b/src/Filter/GeoBoundingBoxFilter.php
@@ -11,73 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The GeoBoundingBoxFilter class is deprecated and will be removed in 2.0. Use GeoBoundingBoxQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\GeoBoundingBoxQuery;
 
 /**
  * Represents Elasticsearch "Geo Bounding Box" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the GeoBoundingBoxQuery instead.
  */
-class GeoBoundingBoxFilter implements BuilderInterface
+class GeoBoundingBoxFilter extends GeoBoundingBoxQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var array
-     */
-    private $values;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @param string $field
-     * @param array  $values
-     * @param array  $parameters
-     */
-    public function __construct($field, $values, array $parameters = [])
-    {
-        $this->field = $field;
-        $this->values = $values;
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'geo_bounding_box';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        if (count($this->values) === 2) {
-            $query = [
-                $this->field => [
-                    'top_left' => $this->values[0],
-                    'bottom_right' => $this->values[1],
-                ],
-            ];
-        } elseif (count($this->values) === 4) {
-            $query = [
-                $this->field => [
-                    'top' => $this->values[0],
-                    'left' => $this->values[1],
-                    'bottom' => $this->values[2],
-                    'right' => $this->values[3],
-                ],
-            ];
-        } else {
-            throw new \LogicException('Geo Bounding Box filter must have 2 or 4 geo points set.');
-        }
-
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/GeoDistanceFilter.php b/src/Filter/GeoDistanceFilter.php
index 7346918..0de010f 100644
--- a/src/Filter/GeoDistanceFilter.php
+++ b/src/Filter/GeoDistanceFilter.php
@@ -11,65 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The GeoDistanceFilter class is deprecated and will be removed in 2.0. Use GeoDistanceQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\GeoDistanceQuery;
 
 /**
  * Represents Elasticsearch "Geo Distance Filter" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the GeoDistanceQuery instead.
  */
-class GeoDistanceFilter implements BuilderInterface
+class GeoDistanceFilter extends GeoDistanceQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @var string
-     */
-    private $distance;
-
-    /**
-     * @var mixed
-     */
-    private $location;
-
-    /**
-     * @param string $field
-     * @param string $distance
-     * @param mixed  $location
-     * @param array  $parameters
-     */
-    public function __construct($field, $distance, $location, array $parameters = [])
-    {
-        $this->field = $field;
-        $this->distance = $distance;
-        $this->location = $location;
-
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'geo_distance';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = [
-            'distance' => $this->distance,
-            $this->field => $this->location,
-        ];
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/GeoDistanceRangeFilter.php b/src/Filter/GeoDistanceRangeFilter.php
index ba433ab..44a24f9 100644
--- a/src/Filter/GeoDistanceRangeFilter.php
+++ b/src/Filter/GeoDistanceRangeFilter.php
@@ -11,62 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The GeoDistanceRangeFilter class is deprecated and will be removed in 2.0. Use GeoDistanceRangeQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\GeoDistanceRangeQuery;
 
 /**
  * Represents Elasticsearch "Geo Distance Range Filter" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the GeoDistanceRangeQuery instead.
  */
-class GeoDistanceRangeFilter implements BuilderInterface
+class GeoDistanceRangeFilter extends GeoDistanceRangeQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @var array
-     */
-    private $range;
-
-    /**
-     * @var mixed
-     */
-    private $location;
-
-    /**
-     * @param string $field
-     * @param array  $range
-     * @param mixed  $location
-     * @param array  $parameters
-     */
-    public function __construct($field, $range, $location, array $parameters = [])
-    {
-        $this->field = $field;
-        $this->range = $range;
-        $this->location = $location;
-
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'geo_distance_range';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = $this->range + [$this->field => $this->location];
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/GeoPolygonFilter.php b/src/Filter/GeoPolygonFilter.php
index 541f395..3340aea 100644
--- a/src/Filter/GeoPolygonFilter.php
+++ b/src/Filter/GeoPolygonFilter.php
@@ -11,55 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The GeoPolygonFilter class is deprecated and will be removed in 2.0. Use GeoPolygonQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\GeoPolygonQuery;
 
 /**
  * Elasticsearch geo polygon filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the GeoPolygonQuery instead.
  */
-class GeoPolygonFilter implements BuilderInterface
+class GeoPolygonFilter extends GeoPolygonQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @var array
-     */
-    private $points;
-
-    /**
-     * @param string $field
-     * @param array  $points
-     * @param array  $parameters
-     */
-    public function __construct($field, array $points = [], array $parameters = [])
-    {
-        $this->field = $field;
-        $this->points = $points;
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'geo_polygon';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = [];
-        $query[$this->field] = ['points' => $this->points];
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/GeoShapeFilter.php b/src/Filter/GeoShapeFilter.php
index 0c83b81..d783268 100644
--- a/src/Filter/GeoShapeFilter.php
+++ b/src/Filter/GeoShapeFilter.php
@@ -11,90 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The GeoShapeFilter class is deprecated and will be removed in 2.0. Use GeoShapeQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\GeoShapeQuery;
 
 /**
  * Elasticsearch geo-shape filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the GeoShapeQuery instead.
  */
-class GeoShapeFilter implements BuilderInterface
+class GeoShapeFilter extends GeoShapeQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var array
-     */
-    private $fields = [];
-
-    /**
-     * @param array $parameters
-     */
-    public function __construct(array $parameters = [])
-    {
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'geo_shape';
-    }
-
-    /**
-     * Add geo-shape provided filter.
-     *
-     * @param string $field       Field name.
-     * @param string $type        Shape type.
-     * @param array  $coordinates Shape coordinates.
-     * @param array  $parameters  Additional parameters.
-     */
-    public function addShape($field, $type, array $coordinates, array $parameters = [])
-    {
-        $filter = array_merge(
-            $parameters,
-            [
-                'type' => $type,
-                'coordinates' => $coordinates,
-            ]
-        );
-
-        $this->fields[$field]['shape'] = $filter;
-    }
-
-    /**
-     * Add geo-shape pre-indexed filter.
-     *
-     * @param string $field      Field name.
-     * @param string $id         The ID of the document that containing the pre-indexed shape.
-     * @param string $type       Name of the index where the pre-indexed shape is.
-     * @param string $index      Index type where the pre-indexed shape is.
-     * @param string $path       The field specified as path containing the pre-indexed shape.
-     * @param array  $parameters Additional parameters.
-     */
-    public function addPreIndexedShape($field, $id, $type, $index, $path, array $parameters = [])
-    {
-        $filter = array_merge(
-            $parameters,
-            [
-                'id' => $id,
-                'type' => $type,
-                'index' => $index,
-                'path' => $path,
-            ]
-        );
-
-        $this->fields[$field]['indexed_shape'] = $filter;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $output = $this->processArray($this->fields);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/GeohashCellFilter.php b/src/Filter/GeohashCellFilter.php
index 993420c..768f02b 100644
--- a/src/Filter/GeohashCellFilter.php
+++ b/src/Filter/GeohashCellFilter.php
@@ -11,56 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The GeohashCellFilter class is deprecated and will be removed in 2.0. Use GeohashCellQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\GeohashCellQuery;
 
 /**
  * Represents Elasticsearch "Geohash Cell" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the GeohashCellQuery instead.
  */
-class GeohashCellFilter implements BuilderInterface
+class GeohashCellFilter extends GeohashCellQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @var mixed
-     */
-    private $location;
-
-    /**
-     * @param string $field
-     * @param mixed  $location
-     * @param array  $parameters
-     */
-    public function __construct($field, $location, array $parameters = [])
-    {
-        $this->field = $field;
-        $this->location = $location;
-
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'geohash_cell';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = [];
-        $query[$this->field] = $this->location;
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/HasChildFilter.php b/src/Filter/HasChildFilter.php
index 4f0c585..de79c65 100644
--- a/src/Filter/HasChildFilter.php
+++ b/src/Filter/HasChildFilter.php
@@ -11,49 +11,32 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The HasChildFilter class is deprecated and will be removed in 2.0. Use HasChildQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\DslTypeAwareTrait;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+use ONGR\ElasticsearchDSL\Query\HasChildQuery;
 
 /**
  * Elasticsearch has_child filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the BoolQuery instead.
  */
-class HasChildFilter implements BuilderInterface
+class HasChildFilter extends HasChildQuery
 {
-    use ParametersTrait;
     use DslTypeAwareTrait;
 
     /**
-     * @var string
-     */
-    private $type;
-
-    /**
-     * @var BuilderInterface
-     */
-    private $query;
-
-    /**
-     * @param string           $type
-     * @param BuilderInterface $query
-     * @param array            $parameters
-     *
-     * @throws \InvalidArgumentException
+     * {@inheritdoc}
      */
     public function __construct($type, BuilderInterface $query, array $parameters = [])
     {
-        $this->type = $type;
-        $this->query = $query;
-        $this->setParameters($parameters);
         $this->setDslType('filter');
-    }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'has_child';
+        parent::__construct($type, $query, $parameters);
     }
 
     /**
@@ -61,13 +44,13 @@ class HasChildFilter implements BuilderInterface
      */
     public function toArray()
     {
-        $query = [
-            'type' => $this->type,
-            $this->getDslType() => [$this->query->getType() => $this->query->toArray()],
-        ];
+        $result = parent::toArray();
 
-        $output = $this->processArray($query);
+        if ($this->getDslType() !== 'query') {
+            $result[$this->getDslType()] = $result['query'];
+            unset($result['query']);
+        }
 
-        return $output;
+        return $result;
     }
 }
diff --git a/src/Filter/HasParentFilter.php b/src/Filter/HasParentFilter.php
index 5bb372d..90212bc 100644
--- a/src/Filter/HasParentFilter.php
+++ b/src/Filter/HasParentFilter.php
@@ -11,49 +11,32 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The HasParentFilter class is deprecated and will be removed in 2.0. Use HasParentQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\DslTypeAwareTrait;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+use ONGR\ElasticsearchDSL\Query\HasParentQuery;
 
 /**
  * Elasticsearch has_parent filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the HasParentQuery instead.
  */
-class HasParentFilter implements BuilderInterface
+class HasParentFilter extends HasParentQuery
 {
-    use ParametersTrait;
     use DslTypeAwareTrait;
 
     /**
-     * @var string
-     */
-    private $parentType;
-
-    /**
-     * @var BuilderInterface
-     */
-    private $query;
-
-    /**
-     * @param string           $parentType
-     * @param BuilderInterface $query
-     * @param array            $parameters
-     *
-     * @throws \InvalidArgumentException
+     * {@inheritdoc}
      */
-    public function __construct($parentType, BuilderInterface $query, array $parameters = [])
+    public function __construct($type, BuilderInterface $query, array $parameters = [])
     {
-        $this->parentType = $parentType;
-        $this->query = $query;
-        $this->setParameters($parameters);
         $this->setDslType('filter');
-    }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'has_parent';
+        parent::__construct($type, $query, $parameters);
     }
 
     /**
@@ -61,13 +44,13 @@ class HasParentFilter implements BuilderInterface
      */
     public function toArray()
     {
-        $query = [
-            'parent_type' => $this->parentType,
-            $this->getDslType() => [$this->query->getType() => $this->query->toArray()],
-        ];
+        $result = parent::toArray();
 
-        $output = $this->processArray($query);
+        if ($this->getDslType() !== 'query') {
+            $result[$this->getDslType()] = $result['query'];
+            unset($result['query']);
+        }
 
-        return $output;
+        return $result;
     }
 }
diff --git a/src/Filter/IdsFilter.php b/src/Filter/IdsFilter.php
index 4ceefa9..64a195e 100644
--- a/src/Filter/IdsFilter.php
+++ b/src/Filter/IdsFilter.php
@@ -11,49 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The IdsFilter class is deprecated and will be removed in 2.0. Use IdsQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\IdsQuery;
 
 /**
  * Represents Elasticsearch "ids" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the IdsQuery instead.
  */
-class IdsFilter implements BuilderInterface
+class IdsFilter extends IdsQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string[]
-     */
-    private $values;
-
-    /**
-     * @param string[] $values     Ids' values.
-     * @param array    $parameters Optional parameters.
-     */
-    public function __construct($values, array $parameters = [])
-    {
-        $this->values = $values;
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'ids';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = [];
-        $query['values'] = $this->values;
-
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/IndicesFilter.php b/src/Filter/IndicesFilter.php
index 0010552..a2f829a 100644
--- a/src/Filter/IndicesFilter.php
+++ b/src/Filter/IndicesFilter.php
@@ -11,10 +11,17 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The IndicesFilter class is deprecated and will be removed in 2.0. Use IndicesQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 
 /**
  * Represents Elasticsearch "indices" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the IndicesQuery instead.
  */
 class IndicesFilter implements BuilderInterface
 {
diff --git a/src/Filter/LimitFilter.php b/src/Filter/LimitFilter.php
index 18d254b..b870f8a 100644
--- a/src/Filter/LimitFilter.php
+++ b/src/Filter/LimitFilter.php
@@ -11,43 +11,20 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
+@trigger_error(
+    'The LimitFilter class is deprecated and will be removed in 2.0. Use LimitQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\LimitQuery;
 
 /**
  * Represents Elasticsearch "limit" filter.
  *
  * A limit filter limits the number of documents (per shard) to execute on.
+ *
+ * @deprecated Will be removed in 2.0. Use the LimitQuery instead.
  */
-class LimitFilter implements BuilderInterface
+class LimitFilter extends LimitQuery
 {
-    /**
-     * @var int
-     */
-    private $value;
-
-    /**
-     * @param int $value Number of documents (per shard) to execute on.
-     */
-    public function __construct($value)
-    {
-        $this->value = $value;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'limit';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        return [
-            'value' => $this->value,
-        ];
-    }
 }
diff --git a/src/Filter/MatchAllFilter.php b/src/Filter/MatchAllFilter.php
index 7674a01..30c15c2 100644
--- a/src/Filter/MatchAllFilter.php
+++ b/src/Filter/MatchAllFilter.php
@@ -11,28 +11,20 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
+@trigger_error(
+    'The MatchAllFilter class is deprecated and will be removed in 2.0. Use MatchAllQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
 
 /**
  * Represents Elasticsearch "match_all" filter.
  *
  * A filter matches on all documents.
+ *
+ * @deprecated Will be removed in 2.0. Use the MatchAllQuery instead.
  */
-class MatchAllFilter implements BuilderInterface
+class MatchAllFilter extends MatchAllQuery
 {
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'match_all';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        return [];
-    }
 }
diff --git a/src/Filter/MissingFilter.php b/src/Filter/MissingFilter.php
index 776a1bd..a1102dd 100644
--- a/src/Filter/MissingFilter.php
+++ b/src/Filter/MissingFilter.php
@@ -11,49 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The MissingFilter class is deprecated and will be removed in 2.0. Use MissingQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\MissingQuery;
 
 /**
  * Represents Elasticsearch "missing" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the MissingQuery instead.
  */
-class MissingFilter implements BuilderInterface
+class MissingFilter extends MissingQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @param string $field      Field name.
-     * @param array  $parameters Optional parameters.
-     */
-    public function __construct($field, array $parameters = [])
-    {
-        $this->field = $field;
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'missing';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = [];
-        $query['field'] = $this->field;
-
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/NestedFilter.php b/src/Filter/NestedFilter.php
index 6b466a4..1202802 100644
--- a/src/Filter/NestedFilter.php
+++ b/src/Filter/NestedFilter.php
@@ -11,60 +11,29 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The NestedFilter class is deprecated and will be removed in 2.0. Use NestedQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\NestedQuery;
 
 /**
  * Nested filter implementation.
+ *
+ * @deprecated Will be removed in 2.0. Use the NestedQuery instead.
  */
-class NestedFilter implements BuilderInterface
+class NestedFilter extends NestedQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $path;
-
-    /**
-     * @var BuilderInterface
-     */
-    private $query;
-
-    /**
-     * @param string           $path
-     * @param BuilderInterface $query
-     * @param array            $parameters
-     */
-    public function __construct($path, BuilderInterface $query, array $parameters = [])
-    {
-        $this->path = $path;
-        $this->query = $query;
-        $this->parameters = $parameters;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'nested';
-    }
-
     /**
      * {@inheritdoc}
      */
     public function toArray()
     {
-        $query = [
-            'path' => $this->path,
-            'filter' => [
-                $this->query->getType() => $this->query->toArray(),
-            ],
-        ];
-
-        $output = $this->processArray($query);
+        $result = parent::toArray();
+        $result['filter'] = $result['query'];
+        unset($result['query']);
 
-        return $output;
+        return $result;
     }
 }
diff --git a/src/Filter/NotFilter.php b/src/Filter/NotFilter.php
index 8590ba4..d43653f 100644
--- a/src/Filter/NotFilter.php
+++ b/src/Filter/NotFilter.php
@@ -11,6 +11,11 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The NotFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
@@ -18,6 +23,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
  * Represents Elasticsearch "not" filter.
  *
  * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-not-filter.html
+ *
+ * @deprecated Will be removed in 2.0. Use the BoolQuery instead.
  */
 class NotFilter implements BuilderInterface
 {
diff --git a/src/Filter/OrFilter.php b/src/Filter/OrFilter.php
index 53e2258..834b99e 100644
--- a/src/Filter/OrFilter.php
+++ b/src/Filter/OrFilter.php
@@ -11,10 +11,17 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The OrFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
+    E_USER_DEPRECATED
+);
+
 /**
  * Represents Elasticsearch "or" filter.
  *
  * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-or-filter.html
+ *
+ * @deprecated Will be removed in 2.0. Use the BoolQuery instead.
  */
 class OrFilter extends AndFilter
 {
diff --git a/src/Filter/PrefixFilter.php b/src/Filter/PrefixFilter.php
index 4d37438..78d15ec 100644
--- a/src/Filter/PrefixFilter.php
+++ b/src/Filter/PrefixFilter.php
@@ -11,48 +11,22 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The PrefixFilter class is deprecated and will be removed in 2.0. Use PrefixQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\PrefixQuery;
 
 /**
  * Represents Elasticsearch "prefix" filter.
  *
  * Filters documents that have fields containing terms with a specified prefix.
+ *
+ * @deprecated Will be removed in 2.0. Use the PrefixQuery instead.
  */
-class PrefixFilter implements BuilderInterface
+class PrefixFilter extends PrefixQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    protected $field;
-
-    /**
-     * @var string
-     */
-    protected $value;
-
-    /**
-     * @param string $field      Field name.
-     * @param string $value      Value.
-     * @param array  $parameters Optional parameters.
-     */
-    public function __construct($field, $value, array $parameters = [])
-    {
-        $this->field = $field;
-        $this->value = $value;
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'prefix';
-    }
-
     /**
      * {@inheritdoc}
      */
diff --git a/src/Filter/QueryFilter.php b/src/Filter/QueryFilter.php
index 7144ba3..f9f23cb 100644
--- a/src/Filter/QueryFilter.php
+++ b/src/Filter/QueryFilter.php
@@ -11,11 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The QueryFilter class is deprecated and will be removed in 2.0.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
  * Represents Elasticsearch "query" filter.
+ *
+ * @deprecated Will be removed in 2.0. The query filter has been removed as queries and filters have been merged.
  */
 class QueryFilter implements BuilderInterface
 {
diff --git a/src/Filter/RangeFilter.php b/src/Filter/RangeFilter.php
index 970f568..c891684 100644
--- a/src/Filter/RangeFilter.php
+++ b/src/Filter/RangeFilter.php
@@ -11,28 +11,22 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The RangeFilter class is deprecated and will be removed in 2.0. Use RangeQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\RangeQuery;
 
 /**
  * Represents Elasticsearch "range" filter.
  *
  * Filters documents with fields that have terms within a certain range.
+ *
+ * @deprecated Will be removed in 2.0. Use the RangeQuery instead.
  */
-class RangeFilter implements BuilderInterface
+class RangeFilter extends RangeQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @var array
-     */
-    private $range;
-
     /**
      * @param string $field      Field name.
      * @param array  $range      Range values.
@@ -40,28 +34,6 @@ class RangeFilter implements BuilderInterface
      */
     public function __construct($field, $range, array $parameters = [])
     {
-        $this->field = $field;
-        $this->range = $range;
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'range';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = [$this->field => $this->range];
-
-        $output = $this->processArray($query);
-
-        return $output;
+        parent::__construct($field, array_merge($range, $parameters));
     }
 }
diff --git a/src/Filter/RegexpFilter.php b/src/Filter/RegexpFilter.php
index 20ef0e6..1bc03ec 100644
--- a/src/Filter/RegexpFilter.php
+++ b/src/Filter/RegexpFilter.php
@@ -11,11 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The RegexpFilter class is deprecated and will be removed in 2.0. Use RegexpQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
  * Represents Elasticsearch "regexp" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the RegexpQuery instead.
  */
 class RegexpFilter implements BuilderInterface
 {
diff --git a/src/Filter/ScriptFilter.php b/src/Filter/ScriptFilter.php
index 1ee2466..5b751cd 100644
--- a/src/Filter/ScriptFilter.php
+++ b/src/Filter/ScriptFilter.php
@@ -11,6 +11,11 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
+@trigger_error(
+    'The ScriptFilter class is deprecated and will be removed in 2.0. Use ScriptQuery instead.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
@@ -18,6 +23,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
  * Represents Elasticsearch "script" filter.
  *
  * Allows to define scripts as filters.
+ *
+ * @deprecated Will be removed in 2.0. Use the ScriptQuery instead.
  */
 class ScriptFilter implements BuilderInterface
 {
diff --git a/src/Filter/TermFilter.php b/src/Filter/TermFilter.php
index 743108a..fade730 100644
--- a/src/Filter/TermFilter.php
+++ b/src/Filter/TermFilter.php
@@ -11,16 +11,20 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The TermFilter class is deprecated and will be removed in 2.0. Use TermQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\TermQuery;
 
 /**
  * Represents Elasticsearch "term" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the TermQuery instead.
  */
-class TermFilter implements BuilderInterface
+class TermFilter extends TermQuery
 {
-    use ParametersTrait;
-
     /**
      * @var string
      */
@@ -29,26 +33,17 @@ class TermFilter implements BuilderInterface
     /**
      * @var string
      */
-    private $term;
+    private $value;
 
     /**
-     * @param string $field      Field name.
-     * @param string $term       Field value.
-     * @param array  $parameters Optional parameters.
+     * {@inheritdoc}
      */
-    public function __construct($field, $term, array $parameters = [])
+    public function __construct($field, $value, array $parameters = [])
     {
         $this->field = $field;
-        $this->term = $term;
-        $this->setParameters($parameters);
-    }
+        $this->value = $value;
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'term';
+        parent::__construct($field, $value, $parameters);
     }
 
     /**
@@ -56,7 +51,7 @@ class TermFilter implements BuilderInterface
      */
     public function toArray()
     {
-        $query = [$this->field => $this->term];
+        $query = [$this->field => $this->value];
 
         $output = $this->processArray($query);
 
diff --git a/src/Filter/TermsFilter.php b/src/Filter/TermsFilter.php
index 672814a..c42fff8 100644
--- a/src/Filter/TermsFilter.php
+++ b/src/Filter/TermsFilter.php
@@ -11,55 +11,18 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
-use ONGR\ElasticsearchDSL\ParametersTrait;
+@trigger_error(
+    'The TermsFilter class is deprecated and will be removed in 2.0. Use TermsQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\TermsQuery;
 
 /**
  * Represents Elasticsearch "terms" filter.
+ *
+ * @deprecated Will be removed in 2.0. Use the TermsQuery instead.
  */
-class TermsFilter implements BuilderInterface
+class TermsFilter extends TermsQuery
 {
-    use ParametersTrait;
-
-    /**
-     * @var string
-     */
-    private $field;
-
-    /**
-     * @var array
-     */
-    private $terms;
-
-    /**
-     * @param string $field      Field name.
-     * @param array  $terms      An array of terms.
-     * @param array  $parameters Optional parameters.
-     */
-    public function __construct($field, $terms, array $parameters = [])
-    {
-        $this->field = $field;
-        $this->terms = $terms;
-        $this->setParameters($parameters);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'terms';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        $query = [$this->field => $this->terms];
-
-        $output = $this->processArray($query);
-
-        return $output;
-    }
 }
diff --git a/src/Filter/TypeFilter.php b/src/Filter/TypeFilter.php
index 7d947a5..018a59d 100644
--- a/src/Filter/TypeFilter.php
+++ b/src/Filter/TypeFilter.php
@@ -11,45 +11,20 @@
 
 namespace ONGR\ElasticsearchDSL\Filter;
 
-use ONGR\ElasticsearchDSL\BuilderInterface;
+@trigger_error(
+    'The TypeFilter class is deprecated and will be removed in 2.0. Use TypeQuery instead.',
+    E_USER_DEPRECATED
+);
+
+use ONGR\ElasticsearchDSL\Query\TypeQuery;
 
 /**
  * Represents Elasticsearch "type" filter.
  *
  * Filters documents matching the provided type.
+ *
+ * @deprecated Will be removed in 2.0. Use the TypeQuery instead.
  */
-class TypeFilter implements BuilderInterface
+class TypeFilter extends TypeQuery
 {
-    /**
-     * @var string
-     */
-    private $type;
-
-    /**
-     * Constructor.
-     *
-     * @param string $type Type name.
-     */
-    public function __construct($type)
-    {
-        $this->type = $type;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getType()
-    {
-        return 'type';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toArray()
-    {
-        return [
-            'value' => $this->type,
-        ];
-    }
 }
diff --git a/src/Query/ExistsQuery.php b/src/Query/ExistsQuery.php
new file mode 100644
index 0000000..1c62382
--- /dev/null
+++ b/src/Query/ExistsQuery.php
@@ -0,0 +1,55 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+
+/**
+ * Represents Elasticsearch "exists" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
+ */
+class ExistsQuery implements BuilderInterface
+{
+    /**
+     * @var string
+     */
+    private $field;
+
+    /**
+     * Constructor.
+     *
+     * @param string $field Field value
+     */
+    public function __construct($field)
+    {
+        $this->field = $field;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'exists';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        return [
+            'field' => $this->field,
+        ];
+    }
+}
diff --git a/src/Query/FilteredQuery.php b/src/Query/FilteredQuery.php
index f7b3dbe..ce68fc5 100644
--- a/src/Query/FilteredQuery.php
+++ b/src/Query/FilteredQuery.php
@@ -11,6 +11,12 @@
 
 namespace ONGR\ElasticsearchDSL\Query;
 
+@trigger_error(
+    'The FilteredQuery class is deprecated and will be removed in 2.0. ' .
+    'Use the "bool" query instead with a "filter" clause.',
+    E_USER_DEPRECATED
+);
+
 use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
@@ -18,6 +24,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
  * Represents Elasticsearch "bool" filter.
  *
  * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html
+ *
+ * @deprecated Will be removed in 2.0. Use the `bool` query instead with a `filter` clause.
  */
 class FilteredQuery implements BuilderInterface
 {
diff --git a/src/Query/GeoBoundingBoxQuery.php b/src/Query/GeoBoundingBoxQuery.php
new file mode 100644
index 0000000..f77ce22
--- /dev/null
+++ b/src/Query/GeoBoundingBoxQuery.php
@@ -0,0 +1,85 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "geo_bounding_box" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html
+ */
+class GeoBoundingBoxQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var array
+     */
+    private $values;
+
+    /**
+     * @var string
+     */
+    private $field;
+
+    /**
+     * @param string $field
+     * @param array  $values
+     * @param array  $parameters
+     */
+    public function __construct($field, $values, array $parameters = [])
+    {
+        $this->field = $field;
+        $this->values = $values;
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'geo_bounding_box';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        if (count($this->values) === 2) {
+            $query = [
+                $this->field => [
+                    'top_left' => $this->values[0],
+                    'bottom_right' => $this->values[1],
+                ],
+            ];
+        } elseif (count($this->values) === 4) {
+            $query = [
+                $this->field => [
+                    'top' => $this->values[0],
+                    'left' => $this->values[1],
+                    'bottom' => $this->values[2],
+                    'right' => $this->values[3],
+                ],
+            ];
+        } else {
+            throw new \LogicException('Geo Bounding Box filter must have 2 or 4 geo points set.');
+        }
+
+        $output = $this->processArray($query);
+
+        return $output;
+    }
+}
diff --git a/src/Query/GeoDistanceQuery.php b/src/Query/GeoDistanceQuery.php
new file mode 100644
index 0000000..477d872
--- /dev/null
+++ b/src/Query/GeoDistanceQuery.php
@@ -0,0 +1,77 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "geo_distance" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
+ */
+class GeoDistanceQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    private $field;
+
+    /**
+     * @var string
+     */
+    private $distance;
+
+    /**
+     * @var mixed
+     */
+    private $location;
+
+    /**
+     * @param string $field
+     * @param string $distance
+     * @param mixed  $location
+     * @param array  $parameters
+     */
+    public function __construct($field, $distance, $location, array $parameters = [])
+    {
+        $this->field = $field;
+        $this->distance = $distance;
+        $this->location = $location;
+
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'geo_distance';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $query = [
+            'distance' => $this->distance,
+            $this->field => $this->location,
+        ];
+        $output = $this->processArray($query);
+
+        return $output;
+    }
+}
diff --git a/src/Query/GeoDistanceRangeQuery.php b/src/Query/GeoDistanceRangeQuery.php
new file mode 100644
index 0000000..ab9a8a3
--- /dev/null
+++ b/src/Query/GeoDistanceRangeQuery.php
@@ -0,0 +1,74 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "geo_distance_range" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-range-query.html
+ */
+class GeoDistanceRangeQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    private $field;
+
+    /**
+     * @var array
+     */
+    private $range;
+
+    /**
+     * @var mixed
+     */
+    private $location;
+
+    /**
+     * @param string $field
+     * @param array  $range
+     * @param mixed  $location
+     * @param array  $parameters
+     */
+    public function __construct($field, $range, $location, array $parameters = [])
+    {
+        $this->field = $field;
+        $this->range = $range;
+        $this->location = $location;
+
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'geo_distance_range';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $query = $this->range + [$this->field => $this->location];
+        $output = $this->processArray($query);
+
+        return $output;
+    }
+}
diff --git a/src/Query/GeoPolygonQuery.php b/src/Query/GeoPolygonQuery.php
new file mode 100644
index 0000000..680ed8e
--- /dev/null
+++ b/src/Query/GeoPolygonQuery.php
@@ -0,0 +1,66 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "geo_polygon" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html
+ */
+class GeoPolygonQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    private $field;
+
+    /**
+     * @var array
+     */
+    private $points;
+
+    /**
+     * @param string $field
+     * @param array  $points
+     * @param array  $parameters
+     */
+    public function __construct($field, array $points = [], array $parameters = [])
+    {
+        $this->field = $field;
+        $this->points = $points;
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'geo_polygon';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $query = [$this->field => ['points' => $this->points]];
+        $output = $this->processArray($query);
+
+        return $output;
+    }
+}
diff --git a/src/Query/GeoShapeQuery.php b/src/Query/GeoShapeQuery.php
new file mode 100644
index 0000000..4360c85
--- /dev/null
+++ b/src/Query/GeoShapeQuery.php
@@ -0,0 +1,102 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "geo_shape" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
+ */
+class GeoShapeQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var array
+     */
+    private $fields = [];
+
+    /**
+     * @param array $parameters
+     */
+    public function __construct(array $parameters = [])
+    {
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'geo_shape';
+    }
+
+    /**
+     * Add geo-shape provided filter.
+     *
+     * @param string $field       Field name.
+     * @param string $type        Shape type.
+     * @param array  $coordinates Shape coordinates.
+     * @param array  $parameters  Additional parameters.
+     */
+    public function addShape($field, $type, array $coordinates, array $parameters = [])
+    {
+        $filter = array_merge(
+            $parameters,
+            [
+                'type' => $type,
+                'coordinates' => $coordinates,
+            ]
+        );
+
+        $this->fields[$field]['shape'] = $filter;
+    }
+
+    /**
+     * Add geo-shape pre-indexed filter.
+     *
+     * @param string $field      Field name.
+     * @param string $id         The ID of the document that containing the pre-indexed shape.
+     * @param string $type       Name of the index where the pre-indexed shape is.
+     * @param string $index      Index type where the pre-indexed shape is.
+     * @param string $path       The field specified as path containing the pre-indexed shape.
+     * @param array  $parameters Additional parameters.
+     */
+    public function addPreIndexedShape($field, $id, $type, $index, $path, array $parameters = [])
+    {
+        $filter = array_merge(
+            $parameters,
+            [
+                'id' => $id,
+                'type' => $type,
+                'index' => $index,
+                'path' => $path,
+            ]
+        );
+
+        $this->fields[$field]['indexed_shape'] = $filter;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $output = $this->processArray($this->fields);
+
+        return $output;
+    }
+}
diff --git a/src/Query/GeohashCellQuery.php b/src/Query/GeohashCellQuery.php
new file mode 100644
index 0000000..8c54a7d
--- /dev/null
+++ b/src/Query/GeohashCellQuery.php
@@ -0,0 +1,67 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "geohash_cell" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-query.html
+ */
+class GeohashCellQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    private $field;
+
+    /**
+     * @var mixed
+     */
+    private $location;
+
+    /**
+     * @param string $field
+     * @param mixed  $location
+     * @param array  $parameters
+     */
+    public function __construct($field, $location, array $parameters = [])
+    {
+        $this->field = $field;
+        $this->location = $location;
+
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'geohash_cell';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $query = [$this->field => $this->location];
+        $output = $this->processArray($query);
+
+        return $output;
+    }
+}
diff --git a/src/Query/HasChildQuery.php b/src/Query/HasChildQuery.php
index b40462f..e122140 100644
--- a/src/Query/HasChildQuery.php
+++ b/src/Query/HasChildQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch has_child query class.
+ * Represents Elasticsearch "has_child" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html
  */
 class HasChildQuery implements BuilderInterface
 {
diff --git a/src/Query/HasParentQuery.php b/src/Query/HasParentQuery.php
index 1fb1816..4b98a0e 100644
--- a/src/Query/HasParentQuery.php
+++ b/src/Query/HasParentQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch has_parent query class.
+ * Represents Elasticsearch "has_parent" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html
  */
 class HasParentQuery implements BuilderInterface
 {
diff --git a/src/Query/IdsQuery.php b/src/Query/IdsQuery.php
index 5b2b3ad..60cf333 100644
--- a/src/Query/IdsQuery.php
+++ b/src/Query/IdsQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch ids query class.
+ * Represents Elasticsearch "ids" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
  */
 class IdsQuery implements BuilderInterface
 {
diff --git a/src/Query/IndicesQuery.php b/src/Query/IndicesQuery.php
index 8633f21..501ba16 100644
--- a/src/Query/IndicesQuery.php
+++ b/src/Query/IndicesQuery.php
@@ -14,7 +14,9 @@ namespace ONGR\ElasticsearchDSL\Query;
 use ONGR\ElasticsearchDSL\BuilderInterface;
 
 /**
- * Elasticsearch indices query class.
+ * Represents Elasticsearch "indices" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-query.html
  */
 class IndicesQuery implements BuilderInterface
 {
diff --git a/src/Query/LimitQuery.php b/src/Query/LimitQuery.php
new file mode 100644
index 0000000..939b913
--- /dev/null
+++ b/src/Query/LimitQuery.php
@@ -0,0 +1,53 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+
+/**
+ * Represents Elasticsearch "limit" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-limit-query.html
+ */
+class LimitQuery implements BuilderInterface
+{
+    /**
+     * @var int
+     */
+    private $value;
+
+    /**
+     * @param int $value Number of documents (per shard) to execute on
+     */
+    public function __construct($value)
+    {
+        $this->value = $value;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'limit';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        return [
+            'value' => $this->value,
+        ];
+    }
+}
diff --git a/src/Query/MatchAllQuery.php b/src/Query/MatchAllQuery.php
index b8a86da..88ce0b6 100644
--- a/src/Query/MatchAllQuery.php
+++ b/src/Query/MatchAllQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch match_all query class.
+ * Represents Elasticsearch "bool" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
  */
 class MatchAllQuery implements BuilderInterface
 {
diff --git a/src/Query/MissingQuery.php b/src/Query/MissingQuery.php
new file mode 100644
index 0000000..2acb7db
--- /dev/null
+++ b/src/Query/MissingQuery.php
@@ -0,0 +1,61 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "missing" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-missing-query.html
+ */
+class MissingQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    private $field;
+
+    /**
+     * Constructor.
+     *
+     * @param string $field      Field name
+     * @param array  $parameters Optional parameters
+     */
+    public function __construct($field, array $parameters = [])
+    {
+        $this->field = $field;
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'missing';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $query = ['field' => $this->field];
+        $output = $this->processArray($query);
+
+        return $output;
+    }
+}
diff --git a/src/Query/NestedQuery.php b/src/Query/NestedQuery.php
index b9196fa..76a30aa 100644
--- a/src/Query/NestedQuery.php
+++ b/src/Query/NestedQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch nested query class.
+ * Represents Elasticsearch "nested" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
  */
 class NestedQuery implements BuilderInterface
 {
@@ -34,11 +36,13 @@ class NestedQuery implements BuilderInterface
     /**
      * @param string           $path
      * @param BuilderInterface $query
+     * @param array            $parameters
      */
-    public function __construct($path, BuilderInterface $query)
+    public function __construct($path, BuilderInterface $query, array $parameters = [])
     {
         $this->path = $path;
         $this->query = $query;
+        $this->parameters = $parameters;
     }
 
     /**
diff --git a/src/Query/PrefixQuery.php b/src/Query/PrefixQuery.php
index 09e655e..9f99411 100644
--- a/src/Query/PrefixQuery.php
+++ b/src/Query/PrefixQuery.php
@@ -11,13 +11,48 @@
 
 namespace ONGR\ElasticsearchDSL\Query;
 
-use ONGR\ElasticsearchDSL\Filter\PrefixFilter;
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
  * Represents Elasticsearch "prefix" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html
  */
-class PrefixQuery extends PrefixFilter
+class PrefixQuery implements BuilderInterface
 {
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    protected $field;
+
+    /**
+     * @var string
+     */
+    protected $value;
+
+    /**
+     * @param string $field      Field name.
+     * @param string $value      Value.
+     * @param array  $parameters Optional parameters.
+     */
+    public function __construct($field, $value, array $parameters = [])
+    {
+        $this->field = $field;
+        $this->value = $value;
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'prefix';
+    }
+
     /**
      * {@inheritdoc}
      */
diff --git a/src/Query/RegexpQuery.php b/src/Query/RegexpQuery.php
index e5ace95..8887000 100644
--- a/src/Query/RegexpQuery.php
+++ b/src/Query/RegexpQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Regexp query class.
+ * Represents Elasticsearch "regexp" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html
  */
 class RegexpQuery implements BuilderInterface
 {
diff --git a/src/Query/ScriptQuery.php b/src/Query/ScriptQuery.php
new file mode 100644
index 0000000..805907b
--- /dev/null
+++ b/src/Query/ScriptQuery.php
@@ -0,0 +1,59 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+use ONGR\ElasticsearchDSL\ParametersTrait;
+
+/**
+ * Represents Elasticsearch "script" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html
+ */
+class ScriptQuery implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    private $script;
+
+    /**
+     * @param string $script     Script
+     * @param array  $parameters Optional parameters
+     */
+    public function __construct($script, array $parameters = [])
+    {
+        $this->script = $script;
+        $this->setParameters($parameters);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'script';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $query = ['inline' => $this->script];
+        $output = $this->processArray($query);
+
+        return ['script' => $output];
+    }
+}
diff --git a/src/Query/TermQuery.php b/src/Query/TermQuery.php
index e561721..d52fff9 100644
--- a/src/Query/TermQuery.php
+++ b/src/Query/TermQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch term query class.
+ * Represents Elasticsearch "term" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
  */
 class TermQuery implements BuilderInterface
 {
diff --git a/src/Query/TermsQuery.php b/src/Query/TermsQuery.php
index a52c062..0c5e544 100644
--- a/src/Query/TermsQuery.php
+++ b/src/Query/TermsQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch terms query class.
+ * Represents Elasticsearch "terms" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
  */
 class TermsQuery implements BuilderInterface
 {
@@ -29,17 +31,19 @@ class TermsQuery implements BuilderInterface
     /**
      * @var array
      */
-    private $tags;
+    private $terms;
 
     /**
-     * @param string $field
-     * @param array  $tags
-     * @param array  $parameters
+     * Constructor.
+     *
+     * @param string $field      Field name
+     * @param array  $terms      An array of terms
+     * @param array  $parameters Optional parameters
      */
-    public function __construct($field, $tags, array $parameters = [])
+    public function __construct($field, $terms, array $parameters = [])
     {
         $this->field = $field;
-        $this->tags = $tags;
+        $this->terms = $terms;
         $this->setParameters($parameters);
     }
 
@@ -57,7 +61,7 @@ class TermsQuery implements BuilderInterface
     public function toArray()
     {
         $query = [
-            $this->field => $this->tags,
+            $this->field => $this->terms,
         ];
 
         $output = $this->processArray($query);
diff --git a/src/Query/TypeQuery.php b/src/Query/TypeQuery.php
new file mode 100644
index 0000000..843fca9
--- /dev/null
+++ b/src/Query/TypeQuery.php
@@ -0,0 +1,55 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\BuilderInterface;
+
+/**
+ * Represents Elasticsearch "type" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html
+ */
+class TypeQuery implements BuilderInterface  // TODO: add test
+{
+    /**
+     * @var string
+     */
+    private $type;
+
+    /**
+     * Constructor.
+     *
+     * @param string $type Type name
+     */
+    public function __construct($type)
+    {
+        $this->type = $type;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'type';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        return [
+            'value' => $this->type,
+        ];
+    }
+}
diff --git a/tests/Filter/RangeFilterTest.php b/tests/Filter/RangeFilterTest.php
index 3c6589b..0b62a10 100644
--- a/tests/Filter/RangeFilterTest.php
+++ b/tests/Filter/RangeFilterTest.php
@@ -35,9 +35,14 @@ class RangeFilterTest extends \PHPUnit_Framework_TestCase
             // Case #1.
             ['', [], [], ['' => []]],
             // Case #2.
-            ['foo', [1, 5], [], ['foo' => [0 => 1, 1 => 5]]],
+            ['foo', ['gte' => 1, 'lte' => 5], [], ['foo' => ['gte' => 1, 'lte' => 5]]],
             // Case #3.
-            ['test', ['foo', 'bar'], ['type' => 'acme'], ['test' => [0 => 'foo', 1 => 'bar'], 'type' => 'acme']],
+            [
+                'test',
+                ['gte' => 1, 'lte' => 5],
+                ['type' => 'acme'],
+                ['test' => ['gte' => 1, 'lte' => 5, 'type' => 'acme']]
+            ],
         ];
     }
 
diff --git a/tests/Query/ExistsQueryTest.php b/tests/Query/ExistsQueryTest.php
new file mode 100644
index 0000000..4695fad
--- /dev/null
+++ b/tests/Query/ExistsQueryTest.php
@@ -0,0 +1,29 @@
+<?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\Query;
+
+use ONGR\ElasticsearchDSL\Query\ExistsQuery;
+
+/**
+ * Unit test for ExistsQuery.
+ */
+class ExistsQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests ExistsQuery#toArray() method.
+     */
+    public function testToArray()
+    {
+        $query = new ExistsQuery('bar');
+        $this->assertEquals(['field' => 'bar'], $query->toArray());
+    }
+}
diff --git a/tests/Query/GeoBoundingBoxQueryTest.php b/tests/Query/GeoBoundingBoxQueryTest.php
new file mode 100644
index 0000000..5d297a2
--- /dev/null
+++ b/tests/Query/GeoBoundingBoxQueryTest.php
@@ -0,0 +1,87 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Filter\GeoBoundingBoxFilter;
+
+class GeoBoundingBoxQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Test if exception is thrown when geo points are not set.
+     *
+     * @expectedException \LogicException
+     */
+    public function testGeoBoundBoxFilterException()
+    {
+        $filter = new GeoBoundingBoxFilter('location', []);
+        $filter->toArray();
+    }
+
+    /**
+     * Data provider for testToArray().
+     *
+     * @return array
+     */
+    public function getArrayDataProvider()
+    {
+        return [
+            // Case #1 (2 values).
+            [
+                'location',
+                [
+                    ['lat' => 40.73, 'lon' => -74.1],
+                    ['lat' => 40.01, 'lon' => -71.12],
+                ],
+                ['parameter' => 'value'],
+                [
+                    'location' => [
+                        'top_left' => ['lat' => 40.73, 'lon' => -74.1],
+                        'bottom_right' => ['lat' => 40.01, 'lon' => -71.12],
+                    ],
+                    'parameter' => 'value',
+                ],
+            ],
+            // Case #2 (4 values).
+            [
+                'location',
+                [40.73, -74.1, 40.01, -71.12],
+                ['parameter' => 'value'],
+                [
+                    'location' => [
+                        'top' => 40.73,
+                        'left' => -74.1,
+                        'bottom' => 40.01,
+                        'right' => -71.12,
+                    ],
+                    'parameter' => 'value',
+                ],
+            ],
+        ];
+    }
+
+    /**
+     * Tests toArray method.
+     *
+     * @param string $field      Field name.
+     * @param array  $values     Bounding box values.
+     * @param array  $parameters Optional parameters.
+     * @param array  $expected   Expected result.
+     *
+     * @dataProvider getArrayDataProvider
+     */
+    public function testToArray($field, $values, $parameters, $expected)
+    {
+        $filter = new GeoBoundingBoxFilter($field, $values, $parameters);
+        $result = $filter->toArray();
+        $this->assertEquals($expected, $result);
+    }
+}
diff --git a/tests/Query/GeoDistanceQueryTest.php b/tests/Query/GeoDistanceQueryTest.php
new file mode 100644
index 0000000..5b99600
--- /dev/null
+++ b/tests/Query/GeoDistanceQueryTest.php
@@ -0,0 +1,62 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\GeoDistanceQuery;
+
+class GeoDistanceQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Data provider for testToArray().
+     *
+     * @return array
+     */
+    public function getArrayDataProvider()
+    {
+        return [
+            // Case #1.
+            [
+                'location',
+                '200km',
+                ['lat' => 40, 'lon' => -70],
+                [],
+                ['distance' => '200km', 'location' => ['lat' => 40, 'lon' => -70]],
+            ],
+            // Case #2.
+            [
+                'location',
+                '20km',
+                ['lat' => 0, 'lon' => 0],
+                ['parameter' => 'value'],
+                ['distance' => '20km', 'location' => ['lat' => 0, 'lon' => 0], 'parameter' => 'value'],
+            ],
+        ];
+    }
+
+    /**
+     * Tests toArray() method.
+     *
+     * @param string $field      Field name.
+     * @param string $distance   Distance.
+     * @param array  $location   Location.
+     * @param array  $parameters Optional parameters.
+     * @param array  $expected   Expected result.
+     *
+     * @dataProvider getArrayDataProvider
+     */
+    public function testToArray($field, $distance, $location, $parameters, $expected)
+    {
+        $query = new GeoDistanceQuery($field, $distance, $location, $parameters);
+        $result = $query->toArray();
+        $this->assertEquals($expected, $result);
+    }
+}
diff --git a/tests/Query/GeoDistanceRangeQueryTest.php b/tests/Query/GeoDistanceRangeQueryTest.php
new file mode 100644
index 0000000..d686232
--- /dev/null
+++ b/tests/Query/GeoDistanceRangeQueryTest.php
@@ -0,0 +1,62 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\GeoDistanceRangeQuery;
+
+class GeoDistanceRangeQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Data provider to testToArray.
+     *
+     * @return array
+     */
+    public function getArrayDataProvider()
+    {
+        return [
+            // Case #1.
+            [
+                'location',
+                ['from' => '200km', 'to' => '400km'],
+                ['lat' => 40, 'lon' => -70],
+                [],
+                ['from' => '200km', 'to' => '400km', 'location' => ['lat' => 40, 'lon' => -70]],
+            ],
+            // Case #2.
+            [
+                'location',
+                ['from' => '150km', 'to' => '180km'],
+                ['lat' => 0, 'lon' => 0],
+                ['parameter' => 'value'],
+                ['from' => '150km', 'to' => '180km', 'location' => ['lat' => 0, 'lon' => 0], 'parameter' => 'value'],
+            ],
+        ];
+    }
+
+    /**
+     * Tests toArray method.
+     *
+     * @param string $field      Field name.
+     * @param array  $range      Distance range.
+     * @param array  $location   Location.
+     * @param array  $parameters Optional parameters.
+     * @param array  $expected   Expected result.
+     *
+     * @dataProvider getArrayDataProvider
+     */
+    public function testToArray($field, $range, $location, $parameters, $expected)
+    {
+        $query = new GeoDistanceRangeQuery($field, $range, $location, $parameters);
+        $result = $query->toArray();
+        $this->assertEquals($expected, $result);
+    }
+}
diff --git a/tests/Query/GeoPolygonQueryTest.php b/tests/Query/GeoPolygonQueryTest.php
new file mode 100644
index 0000000..a3444ef
--- /dev/null
+++ b/tests/Query/GeoPolygonQueryTest.php
@@ -0,0 +1,88 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\GeoPolygonQuery;
+
+class GeoPolygonQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Data provider to testToArray.
+     *
+     * @return array
+     */
+    public function getArrayDataProvider()
+    {
+        return [
+            // Case #1.
+            [
+                'location',
+                [
+                    ['lat' => 20, 'lon' => -80],
+                    ['lat' => 30, 'lon' => -40],
+                    ['lat' => 70, 'lon' => -90],
+                ],
+                [],
+                [
+                    'location' => [
+                        'points' => [
+                            ['lat' => 20, 'lon' => -80],
+                            ['lat' => 30, 'lon' => -40],
+                            ['lat' => 70, 'lon' => -90],
+                        ],
+                    ],
+                ],
+            ],
+            // Case #2.
+            [
+                'location',
+                [],
+                ['parameter' => 'value'],
+                [
+                    'location' => ['points' => []],
+                    'parameter' => 'value',
+                ],
+            ],
+            // Case #3.
+            [
+                'location',
+                [
+                    ['lat' => 20, 'lon' => -80],
+                ],
+                ['parameter' => 'value'],
+                [
+                    'location' => [
+                        'points' => [['lat' => 20, 'lon' => -80]],
+                    ],
+                    'parameter' => 'value',
+                ],
+            ],
+        ];
+    }
+
+    /**
+     * Tests toArray method.
+     *
+     * @param string $field      Field name.
+     * @param array  $points     Polygon's points.
+     * @param array  $parameters Optional parameters.
+     * @param array  $expected   Expected result.
+     *
+     * @dataProvider getArrayDataProvider
+     */
+    public function testToArray($field, $points, $parameters, $expected)
+    {
+        $filter = new GeoPolygonQuery($field, $points, $parameters);
+        $result = $filter->toArray();
+        $this->assertEquals($expected, $result);
+    }
+}
diff --git a/tests/Query/GeoShapeQueryTest.php b/tests/Query/GeoShapeQueryTest.php
new file mode 100644
index 0000000..c610c16
--- /dev/null
+++ b/tests/Query/GeoShapeQueryTest.php
@@ -0,0 +1,61 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\GeoShapeQuery;
+
+class GeoShapeQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray() method.
+     */
+    public function testToArray()
+    {
+        $filter = new GeoShapeQuery(['param1' => 'value1']);
+        $filter->addShape('location', 'envelope', [[13, 53], [14, 52]]);
+
+        $expected = [
+            'location' => [
+                'shape' => [
+                    'type' => 'envelope',
+                    'coordinates' => [[13, 53], [14, 52]],
+                ],
+            ],
+            'param1' => 'value1',
+        ];
+
+        $this->assertEquals($expected, $filter->toArray());
+    }
+
+    /**
+     * Test for toArray() in case of pre-indexed shape.
+     */
+    public function testToArrayIndexed()
+    {
+        $filter = new GeoShapeQuery(['param1' => 'value1']);
+        $filter->addPreIndexedShape('location', 'DEU', 'countries', 'shapes', 'location');
+
+        $expected = [
+            'location' => [
+                'indexed_shape' => [
+                    'id' => 'DEU',
+                    'type' => 'countries',
+                    'index' => 'shapes',
+                    'path' => 'location',
+                ],
+            ],
+            'param1' => 'value1',
+        ];
+
+        $this->assertEquals($expected, $filter->toArray());
+    }
+}
diff --git a/tests/Query/GeohashCellQueryTest.php b/tests/Query/GeohashCellQueryTest.php
new file mode 100644
index 0000000..bb0d7db
--- /dev/null
+++ b/tests/Query/GeohashCellQueryTest.php
@@ -0,0 +1,59 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\GeohashCellQuery;
+
+class GeohashCellQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Data provider for testToArray().
+     *
+     * @return array
+     */
+    public function getArrayDataProvider()
+    {
+        return [
+            // Case #1.
+            [
+                'location',
+                ['lat' => 40, 'lon' => -70],
+                [],
+                ['location' => ['lat' => 40, 'lon' => -70]],
+            ],
+            // Case #2.
+            [
+                'location',
+                ['lat' => 0, 'lon' => 0],
+                ['parameter' => 'value'],
+                ['location' => ['lat' => 0, 'lon' => 0], 'parameter' => 'value'],
+            ],
+        ];
+    }
+
+    /**
+     * Tests toArray() method.
+     *
+     * @param string $field      Field name.
+     * @param array  $location   Location.
+     * @param array  $parameters Optional parameters.
+     * @param array  $expected   Expected result.
+     *
+     * @dataProvider getArrayDataProvider
+     */
+    public function testToArray($field, $location, $parameters, $expected)
+    {
+        $query = new GeohashCellQuery($field, $location, $parameters);
+        $result = $query->toArray();
+        $this->assertEquals($expected, $result);
+    }
+}
diff --git a/tests/Query/LimitQueryTest.php b/tests/Query/LimitQueryTest.php
new file mode 100644
index 0000000..7162ebf
--- /dev/null
+++ b/tests/Query/LimitQueryTest.php
@@ -0,0 +1,27 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\LimitQuery;
+
+class LimitQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Test for query toArray() method.
+     */
+    public function testToArray()
+    {
+        $query = new LimitQuery(3);
+        $expectedResult = ['value' => 3];
+        $this->assertEquals($expectedResult, $query->toArray());
+    }
+}
diff --git a/tests/Query/MissingQueryTest.php b/tests/Query/MissingQueryTest.php
new file mode 100644
index 0000000..4db348b
--- /dev/null
+++ b/tests/Query/MissingQueryTest.php
@@ -0,0 +1,48 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\MissingQuery;
+
+class MissingQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Data provider to testGetToArray.
+     *
+     * @return array
+     */
+    public function getArrayDataProvider()
+    {
+        return [
+            // Case 1.
+            ['user', [], ['field' => 'user']],
+            // Case 2.
+            ['user', ['existence' => true], ['field' => 'user', 'existence' => true]],
+        ];
+    }
+
+    /**
+     * Test for query toArray() method.
+     *
+     * @param string $field
+     * @param array  $parameters
+     * @param array  $expected
+     *
+     * @dataProvider getArrayDataProvider
+     */
+    public function testToArray($field, $parameters, $expected)
+    {
+        $query = new MissingQuery($field, $parameters);
+        $result = $query->toArray();
+        $this->assertEquals($expected, $result);
+    }
+}
diff --git a/tests/Query/NestedQueryTest.php b/tests/Query/NestedQueryTest.php
index abf9efa..6d766df 100644
--- a/tests/Query/NestedQueryTest.php
+++ b/tests/Query/NestedQueryTest.php
@@ -13,51 +13,58 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL\Query;
 
 use ONGR\ElasticsearchDSL\Query\BoolQuery;
 use ONGR\ElasticsearchDSL\Query\NestedQuery;
+use ONGR\ElasticsearchDSL\Query\TermsQuery;
 use ONGR\ElasticsearchDSL\Query\TermQuery;
 
 class NestedQueryTest extends \PHPUnit_Framework_TestCase
 {
     /**
-     * Tests toArray method.
+     * Data provider to testGetToArray.
+     *
+     * @return array
      */
-    public function testToArray()
+    public function getArrayDataProvider()
     {
-        $missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchDSL\Filter\MissingFilter')
-            ->setConstructorArgs(['test_field'])
-            ->getMock();
-        $missingFilterMock->expects($this->any())
-            ->method('getType')
-            ->willReturn('test_type');
-        $missingFilterMock->expects($this->any())
-            ->method('toArray')
-            ->willReturn(['testKey' => 'testValue']);
-
-        $result = [
-            'path' => 'test_path',
-            'query' => [
-                'test_type' => ['testKey' => 'testValue'],
+        $query = [
+            'terms' => [
+                'foo' => 'bar',
             ],
         ];
 
-        $query = new NestedQuery('test_path', $missingFilterMock);
-        $this->assertEquals($result, $query->toArray());
+        return [
+            'query_only' => [
+                'product.sub_item',
+                [],
+                ['path' => 'product.sub_item', 'query' => $query],
+            ],
+            'query_with_parameters' => [
+                'product.sub_item',
+                ['_cache' => true, '_name' => 'named_result'],
+                [
+                    'path' => 'product.sub_item',
+                    'query' => $query,
+                    '_cache' => true,
+                    '_name' => 'named_result',
+                ],
+            ],
+        ];
     }
 
     /**
-     * Tests if Nested Query has parameters.
+     * Test for query toArray() method.
+     *
+     * @param string $path
+     * @param array  $parameters
+     * @param array  $expected
+     *
+     * @dataProvider getArrayDataProvider
      */
-    public function testParameters()
+    public function testToArray($path, $parameters, $expected)
     {
-        $nestedQuery = $this->getMockBuilder('ONGR\ElasticsearchDSL\Query\NestedQuery')
-            ->disableOriginalConstructor()
-            ->setMethods(null)
-            ->getMock();
-
-        $this->assertTrue(method_exists($nestedQuery, 'addParameter'), 'Nested query must have addParameter method');
-        $this->assertTrue(method_exists($nestedQuery, 'setParameters'), 'Nested query must have setParameters method');
-        $this->assertTrue(method_exists($nestedQuery, 'getParameters'), 'Nested query must have getParameters method');
-        $this->assertTrue(method_exists($nestedQuery, 'hasParameter'), 'Nested query must have hasParameter method');
-        $this->assertTrue(method_exists($nestedQuery, 'getParameter'), 'Nested query must have getParameter method');
+        $query = new TermsQuery('foo', 'bar');
+        $query = new NestedQuery($path, $query, $parameters);
+        $result = $query->toArray();
+        $this->assertEquals($expected, $result);
     }
 
     /**
diff --git a/tests/Query/ScriptQueryTest.php b/tests/Query/ScriptQueryTest.php
new file mode 100644
index 0000000..ee1e5b7
--- /dev/null
+++ b/tests/Query/ScriptQueryTest.php
@@ -0,0 +1,54 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\ScriptQuery;
+
+class ScriptQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Data provider for testToArray().
+     *
+     * @return array
+     */
+    public function getArrayDataProvider()
+    {
+        return [
+            'simple_script' => [
+                "doc['num1'].value > 1",
+                [],
+                ['script' => ['inline' => "doc['num1'].value > 1"]],
+            ],
+            'script_with_parameters' => [
+                "doc['num1'].value > param1",
+                ['params' => ['param1' => 5]],
+                ['script' => ['inline' => "doc['num1'].value > param1", 'params' => ['param1' => 5]]],
+            ],
+        ];
+    }
+
+    /**
+     * Test for filter toArray() method.
+     *
+     * @param string $script     Script.
+     * @param array  $parameters Optional parameters.
+     * @param array  $expected   Expected values.
+     *
+     * @dataProvider getArrayDataProvider
+     */
+    public function testToArray($script, $parameters, $expected)
+    {
+        $filter = new ScriptQuery($script, $parameters);
+        $result = $filter->toArray();
+        $this->assertEquals($expected, $result);
+    }
+}
diff --git a/tests/Query/TypeQueryTest.php b/tests/Query/TypeQueryTest.php
new file mode 100644
index 0000000..98ca516
--- /dev/null
+++ b/tests/Query/TypeQueryTest.php
@@ -0,0 +1,27 @@
+<?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\DSL\Query;
+
+use ONGR\ElasticsearchDSL\Query\TypeQuery;
+
+class TypeQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Test for query toArray() method.
+     */
+    public function testToArray()
+    {
+        $query = new TypeQuery('foo');
+        $expectedResult = ['value' => 'foo'];
+        $this->assertEquals($expectedResult, $query->toArray());
+    }
+}
-- 
GitLab