Skip to content

Commit a76fb50

Browse files
committed
#102033 aggregation functional test
1 parent db3baf6 commit a76fb50

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/Functional/Aggregating/AggregationQueryTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace Ensi\LaravelElasticQuery\Tests\Functional\Aggregating;
44

55
use Ensi\LaravelElasticQuery\Aggregating\AggregationsQuery;
6+
use Ensi\LaravelElasticQuery\Aggregating\Bucket;
7+
use Ensi\LaravelElasticQuery\Aggregating\Metrics\MinMaxScoreAggregation;
68
use Ensi\LaravelElasticQuery\Aggregating\MinMax;
79
use Ensi\LaravelElasticQuery\Contracts\AggregationsBuilder;
10+
use Ensi\LaravelElasticQuery\Search\Sorting\Sort;
811
use Ensi\LaravelElasticQuery\Tests\Functional\ElasticTestCase;
912
use Ensi\LaravelElasticQuery\Tests\Models\ProductsIndex;
1013
use Ensi\LaravelElasticQuery\Tests\Seeds\ProductIndexSeeder;
@@ -77,4 +80,30 @@ public function testTermsSize(): void
7780

7881
$this->assertCount(1, $results->get('codes'));
7982
}
83+
84+
public function testTermsWithSortByCompositeValue(): void
85+
{
86+
$sort = new Sort('score_max');
87+
$composite = new MinMaxScoreAggregation();
88+
89+
$this->testing
90+
->whereMatch('description', 'water')
91+
->where('package', 'bottle')
92+
->terms(
93+
name: 'codes',
94+
field: 'code',
95+
size: 2,
96+
sort: $sort,
97+
composite: $composite
98+
);
99+
100+
$results = $this->testing->get();
101+
102+
$scores = $results->get('codes')->map(
103+
fn (Bucket $bucket) => $bucket->getCompositeValue('score')->max
104+
);
105+
106+
$this->assertCount(2, $results->get('codes'));
107+
$this->assertGreaterThanOrEqual($scores->first(), $scores->last());
108+
}
80109
}

0 commit comments

Comments
 (0)