Skip to content

Commit

Permalink
Add weighted_avg to aggregration DSL (#1814)
Browse files Browse the repository at this point in the history
This follows PR #1771 which added this aggregation but didn't expose it to DSL.
  • Loading branch information
deguif authored Oct 20, 2020
1 parent 8de1dbf commit 2e77058
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Ability to specify the type of authentication manually by the `auth_type` parameter (in the client class config) was added (allowed values are `basic, digest, gssnegotiate, ntlm`)
* Added `if_seq_no` / `if_primary_term` to replace `version` for [optimistic concurrency control](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/optimistic-concurrency-control.html)
* Added `Elastica\Aggregation\PercentilesBucket` aggregation [#1806](https://github.com/ruflin/Elastica/pull/1806)
* Added `weighted_avg` to aggregations DSL [#1814](https://github.com/ruflin/Elastica/pull/1814)
* Supported PHP 8.0 [#1794](https://github.com/ruflin/Elastica/pull/1794)
### Changed
* Allow `string` such as `wait_for` to be passed to `AbstractUpdateAction::setRefresh` [#1791](https://github.com/ruflin/Elastica/pull/1791)
Expand Down
11 changes: 11 additions & 0 deletions src/QueryBuilder/DSL/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Elastica\Aggregation\Terms;
use Elastica\Aggregation\TopHits;
use Elastica\Aggregation\ValueCount;
use Elastica\Aggregation\WeightedAvg;
use Elastica\Exception\NotImplementedException;
use Elastica\Query\AbstractQuery;
use Elastica\QueryBuilder\DSL;
Expand Down Expand Up @@ -442,4 +443,14 @@ public function diversified_sampler(string $name): DiversifiedSampler
{
return new DiversifiedSampler($name);
}

/**
* weighted avg aggregation.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html
*/
public function weighted_avg(string $name): WeightedAvg
{
return new WeightedAvg($name);
}
}
1 change: 1 addition & 0 deletions src/QueryBuilder/Version/Version700.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Version700 extends Version
'geohash_grid',
'bucket_script',
'serial_diff',
'weighted_avg',
];

protected $suggesters = [
Expand Down
1 change: 1 addition & 0 deletions tests/QueryBuilder/DSL/AggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ public function testInterface(): void
$this->_assertImplemented($aggregationDSL, 'adjacency_matrix', Aggregation\AdjacencyMatrix::class, ['name']);
$this->_assertImplemented($aggregationDSL, 'sampler', Aggregation\Sampler::class, ['name']);
$this->_assertImplemented($aggregationDSL, 'diversified_sampler', Aggregation\DiversifiedSampler::class, ['name']);
$this->_assertImplemented($aggregationDSL, 'weighted_avg', Aggregation\WeightedAvg::class, ['name']);
}
}

0 comments on commit 2e77058

Please sign in to comment.