From f2679651c2064383186576f5ffcc3107e4452e57 Mon Sep 17 00:00:00 2001 From: Pawel Krzaczkowski Date: Mon, 17 Feb 2014 12:57:55 +0100 Subject: [PATCH 1/6] Aggragations - prevent global aggregations as sub aggregations --- lib/Elastica/Aggregation/AbstractAggregation.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Elastica/Aggregation/AbstractAggregation.php b/lib/Elastica/Aggregation/AbstractAggregation.php index 3bbc30cff8..d859181b0a 100755 --- a/lib/Elastica/Aggregation/AbstractAggregation.php +++ b/lib/Elastica/Aggregation/AbstractAggregation.php @@ -2,8 +2,8 @@ namespace Elastica\Aggregation; - use Elastica\Param; +use Elastica\Exception\InvalidException; abstract class AbstractAggregation extends Param { @@ -57,10 +57,14 @@ public function getAggs() /** * Add a sub-aggregation * @param AbstractAggregation $aggregation + * @throws \Elastica\Exception\InvalidException * @return AbstractAggregation */ public function addAggregation(AbstractAggregation $aggregation) { + if(is_a($aggregation, 'Elastica\Aggregation\GlobalAggregation')) + throw new InvalidException('Global aggregators can only be placed as top level aggregators'); + $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); return $this; } From 4e7a585fbc41d738d901cc36c3464f92d0f1324d Mon Sep 17 00:00:00 2001 From: Pawel Krzaczkowski Date: Mon, 17 Feb 2014 13:01:49 +0100 Subject: [PATCH 2/6] Aggragations - prevent global aggregations as sub aggregations (changes.txt) --- changes.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changes.txt b/changes.txt index c025c42f9e..d25261bb5c 100755 --- a/changes.txt +++ b/changes.txt @@ -1,4 +1,7 @@ CHANGES +2014-02-17 +- Elastica/Aggregations - global aggragation not allowed as sub aggragation + 2014-02-14 - Add methods setSize, setShardSize to Elastica/Aggregation/Terms - Elastica/Aggregation/GlobalAggregationTest fixed bug where JSON returned [] instead of {} From 34991559242d1c9947d2322524ce4e1d7564f6ee Mon Sep 17 00:00:00 2001 From: Pawel Krzaczkowski Date: Tue, 18 Feb 2014 10:18:54 +0100 Subject: [PATCH 3/6] Aggragations - prevent global aggregations as sub aggregations --- lib/Elastica/Aggregation/AbstractAggregation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Elastica/Aggregation/AbstractAggregation.php b/lib/Elastica/Aggregation/AbstractAggregation.php index d859181b0a..5ad5b17e0f 100755 --- a/lib/Elastica/Aggregation/AbstractAggregation.php +++ b/lib/Elastica/Aggregation/AbstractAggregation.php @@ -62,8 +62,9 @@ public function getAggs() */ public function addAggregation(AbstractAggregation $aggregation) { - if(is_a($aggregation, 'Elastica\Aggregation\GlobalAggregation')) + if(is_a($aggregation, 'Elastica\Aggregation\GlobalAggregation')) { throw new InvalidException('Global aggregators can only be placed as top level aggregators'); + } $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); return $this; From 55e3ca00af6f9d886581a1e1c04790c44865a8f1 Mon Sep 17 00:00:00 2001 From: Pawel Krzaczkowski Date: Mon, 17 Feb 2014 12:57:55 +0100 Subject: [PATCH 4/6] Aggragations - prevent global aggregations as sub aggregations --- lib/Elastica/Aggregation/AbstractAggregation.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Elastica/Aggregation/AbstractAggregation.php b/lib/Elastica/Aggregation/AbstractAggregation.php index 3bbc30cff8..d859181b0a 100755 --- a/lib/Elastica/Aggregation/AbstractAggregation.php +++ b/lib/Elastica/Aggregation/AbstractAggregation.php @@ -2,8 +2,8 @@ namespace Elastica\Aggregation; - use Elastica\Param; +use Elastica\Exception\InvalidException; abstract class AbstractAggregation extends Param { @@ -57,10 +57,14 @@ public function getAggs() /** * Add a sub-aggregation * @param AbstractAggregation $aggregation + * @throws \Elastica\Exception\InvalidException * @return AbstractAggregation */ public function addAggregation(AbstractAggregation $aggregation) { + if(is_a($aggregation, 'Elastica\Aggregation\GlobalAggregation')) + throw new InvalidException('Global aggregators can only be placed as top level aggregators'); + $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); return $this; } From bdc0dcd8de44acc1ae4da47873d89d02f6ca2ea1 Mon Sep 17 00:00:00 2001 From: Pawel Krzaczkowski Date: Mon, 17 Feb 2014 13:01:49 +0100 Subject: [PATCH 5/6] Aggragations - prevent global aggregations as sub aggregations (changes.txt) --- changes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changes.txt b/changes.txt index 4c9f4bc1c9..0f39065b3b 100755 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ CHANGES 2014-02-17 - Throw PartialShardFailureException if response has failed shards +- Issue #555: Elastica/Aggregations/GlobalAggragation not allowed as sub aggragation 2014-02-14 - Add methods setSize, setShardSize to Elastica/Aggregation/Terms From e1f3eb09a56072d1e1fa85c8b205b7d3e4bda368 Mon Sep 17 00:00:00 2001 From: Pawel Krzaczkowski Date: Tue, 18 Feb 2014 10:18:54 +0100 Subject: [PATCH 6/6] Aggragations - prevent global aggregations as sub aggregations --- lib/Elastica/Aggregation/AbstractAggregation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Elastica/Aggregation/AbstractAggregation.php b/lib/Elastica/Aggregation/AbstractAggregation.php index d859181b0a..5ad5b17e0f 100755 --- a/lib/Elastica/Aggregation/AbstractAggregation.php +++ b/lib/Elastica/Aggregation/AbstractAggregation.php @@ -62,8 +62,9 @@ public function getAggs() */ public function addAggregation(AbstractAggregation $aggregation) { - if(is_a($aggregation, 'Elastica\Aggregation\GlobalAggregation')) + if(is_a($aggregation, 'Elastica\Aggregation\GlobalAggregation')) { throw new InvalidException('Global aggregators can only be placed as top level aggregators'); + } $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); return $this;