File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,14 @@ The following query types are available:
206
206
\Spatie\ElasticsearchQueryBuilder\Aggregations\MinAggregation::create('min_price', 'price');
207
207
```
208
208
209
+ #### ` SumAggregation `
210
+
211
+ [ https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html ] ( https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html )
212
+
213
+ ``` php
214
+ \Spatie\ElasticsearchQueryBuilder\Aggregations\SumAggregation::create('sum_price', 'price');
215
+ ```
216
+
209
217
#### ` NestedAggregation `
210
218
211
219
[ https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html ] ( https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html )
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Spatie \ElasticsearchQueryBuilder \Aggregations ;
4
+
5
+ use Spatie \ElasticsearchQueryBuilder \Aggregations \Concerns \WithMissing ;
6
+
7
+ class SumAggregation extends Aggregation
8
+ {
9
+ use WithMissing;
10
+
11
+ protected string $ field ;
12
+
13
+ public static function create (string $ name , string $ field ): self
14
+ {
15
+ return new self ($ name , $ field );
16
+ }
17
+
18
+ public function __construct (string $ name , string $ field )
19
+ {
20
+ $ this ->name = $ name ;
21
+ $ this ->field = $ field ;
22
+ }
23
+
24
+ public function payload (): array
25
+ {
26
+ $ parameters = [
27
+ 'field ' => $ this ->field ,
28
+ ];
29
+
30
+ if ($ this ->missing ) {
31
+ $ parameters ['missing ' ] = $ this ->missing ;
32
+ }
33
+
34
+ return [
35
+ 'sum ' => $ parameters ,
36
+ ];
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments