Skip to content

Commit

Permalink
Aggragations/Filter - fix for es 1.2.0 when no sub aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
krzaczek committed May 27, 2014
1 parent 83fd5c4 commit 09a223c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES

2014-05-27
- Fix Aggragations/Filter to work with es v1.2.0

2014-05-25
- Added Guzzle transport as an alternative to the default Http transport #618
- Added Elastica\ScanAndScroll Iterator (http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/scan-scroll.html) #617
Expand Down
12 changes: 9 additions & 3 deletions lib/Elastica/Aggregation/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ public function setFilter(AbstractFilter $filter)
*/
public function toArray()
{
return array(
"filter" => $this->getParam("filter"),
"aggs" => $this->_aggs
$array = array(
"filter" => $this->getParam("filter")
);

if($this->_aggs)
{
$array['aggs'] = $this->_aggs;
}

return $array;
}
}
15 changes: 15 additions & 0 deletions test/lib/Elastica/Test/Aggregation/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,25 @@ public function testFilterAggregation()

$query = new Query();
$query->addAggregation($agg);

$results = $this->_index->search($query)->getAggregation("filter");
$results = $results['price']['value'];

$this->assertEquals((5 + 8) / 2.0, $results);
}

public function testFilterNoSubAggregation()
{
$agg = new Avg("price");
$agg->setField("price");

$query = new Query();
$query->addAggregation($agg);

$results = $this->_index->search($query)->getAggregation("price");
$results = $results['value'];

$this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results);
}
}

0 comments on commit 09a223c

Please sign in to comment.