Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggragations/Filter - fix for es1.2 when no sub aggregations #619

Merged
merged 1 commit into from
May 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}