Completed
Push — master ( 7c4612...0fe38b )
by Nicolas
01:47
created

Aggregation::sum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Elastica\QueryBuilder\DSL;
4
5
use Elastica\Aggregation\AdjacencyMatrix;
6
use Elastica\Aggregation\Avg;
7
use Elastica\Aggregation\AvgBucket;
8
use Elastica\Aggregation\BucketScript;
9
use Elastica\Aggregation\Cardinality;
10
use Elastica\Aggregation\DateHistogram;
11
use Elastica\Aggregation\DateRange;
12
use Elastica\Aggregation\ExtendedStats;
13
use Elastica\Aggregation\Filter;
14
use Elastica\Aggregation\Filters;
15
use Elastica\Aggregation\GeoDistance;
16
use Elastica\Aggregation\GeohashGrid;
17
use Elastica\Aggregation\GlobalAggregation;
18
use Elastica\Aggregation\Histogram;
19
use Elastica\Aggregation\IpRange;
20
use Elastica\Aggregation\Max;
21
use Elastica\Aggregation\Min;
22
use Elastica\Aggregation\Missing;
23
use Elastica\Aggregation\Nested;
24
use Elastica\Aggregation\Percentiles;
25
use Elastica\Aggregation\Range;
26
use Elastica\Aggregation\ReverseNested;
27
use Elastica\Aggregation\Sampler;
28
use Elastica\Aggregation\ScriptedMetric;
29
use Elastica\Aggregation\SerialDiff;
30
use Elastica\Aggregation\SignificantTerms;
31
use Elastica\Aggregation\Stats;
32
use Elastica\Aggregation\Sum;
33
use Elastica\Aggregation\SumBucket;
34
use Elastica\Aggregation\Terms;
35
use Elastica\Aggregation\TopHits;
36
use Elastica\Aggregation\ValueCount;
37
use Elastica\Exception\NotImplementedException;
38
use Elastica\Query\AbstractQuery;
39
use Elastica\QueryBuilder\DSL;
40
41
/**
42
 * elasticsearch aggregation DSL.
43
 *
44
 * @author Manuel Andreo Garcia <[email protected]>
45
 *
46
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html
47
 */
48
class Aggregation implements DSL
49
{
50
    /**
51
     * must return type for QueryBuilder usage.
52
     *
53
     * @return string
54
     */
55
    public function getType(): string
56
    {
57
        return DSL::TYPE_AGGREGATION;
58
    }
59
60
    /**
61
     * min aggregation.
62
     *
63
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html
64
     *
65
     * @param string $name
66
     *
67
     * @return Min
68
     */
69
    public function min(string $name): Min
70
    {
71
        return new Min($name);
72
    }
73
74
    /**
75
     * max aggregation.
76
     *
77
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
78
     *
79
     * @param string $name
80
     *
81
     * @return Max
82
     */
83
    public function max(string $name): Max
84
    {
85
        return new Max($name);
86
    }
87
88
    /**
89
     * sum aggregation.
90
     *
91
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html
92
     *
93
     * @param string $name
94
     *
95
     * @return Sum
96
     */
97
    public function sum(string $name): Sum
98
    {
99
        return new Sum($name);
100
    }
101
102
    /**
103
     * sum bucket aggregation.
104
     *
105
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html
106
     *
107
     * @param string      $name
108
     * @param string|null $bucketsPath
109
     *
110
     * @return SumBucket
111
     */
112
    public function sum_bucket(string $name, string $bucketsPath = null): SumBucket
113
    {
114
        return new SumBucket($name, $bucketsPath);
115
    }
116
117
    /**
118
     * avg aggregation.
119
     *
120
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
121
     *
122
     * @param string $name
123
     *
124
     * @return Avg
125
     */
126
    public function avg(string $name): Avg
127
    {
128
        return new Avg($name);
129
    }
130
131
    /**
132
     * avg bucket aggregation.
133
     *
134
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
135
     *
136
     * @param string      $name
137
     * @param string|null $bucketsPath
138
     *
139
     * @return AvgBucket
140
     */
141
    public function avg_bucket(string $name, string $bucketsPath = null): AvgBucket
142
    {
143
        return new AvgBucket($name, $bucketsPath);
144
    }
145
146
    /**
147
     * stats aggregation.
148
     *
149
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
150
     *
151
     * @param string $name
152
     *
153
     * @return Stats
154
     */
155
    public function stats(string $name): Stats
156
    {
157
        return new Stats($name);
158
    }
159
160
    /**
161
     * extended stats aggregation.
162
     *
163
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html
164
     *
165
     * @param string $name
166
     *
167
     * @return ExtendedStats
168
     */
169
    public function extended_stats(string $name): ExtendedStats
170
    {
171
        return new ExtendedStats($name);
172
    }
173
174
    /**
175
     * value count aggregation.
176
     *
177
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html
178
     *
179
     * @param string $name
180
     * @param string $field
181
     *
182
     * @return ValueCount
183
     */
184
    public function value_count(string $name, string $field): ValueCount
185
    {
186
        return new ValueCount($name, $field);
187
    }
188
189
    /**
190
     * percentiles aggregation.
191
     *
192
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
193
     *
194
     * @param string $name  the name of this aggregation
195
     * @param string $field the field on which to perform this aggregation
196
     *
197
     * @return Percentiles
198
     */
199
    public function percentiles(string $name, string $field = null): Percentiles
200
    {
201
        return new Percentiles($name, $field);
202
    }
203
204
    /**
205
     * percentile ranks aggregation.
206
     *
207
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html
208
     *
209
     * @param string $name
210
     */
211
    public function percentile_ranks($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
212
    {
213
        throw new NotImplementedException();
214
    }
215
216
    /**
217
     * cardinality aggregation.
218
     *
219
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
220
     *
221
     * @param string $name
222
     *
223
     * @return Cardinality
224
     */
225
    public function cardinality(string $name): Cardinality
226
    {
227
        return new Cardinality($name);
228
    }
229
230
    /**
231
     * geo bounds aggregation.
232
     *
233
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html
234
     *
235
     * @param string $name
236
     */
237
    public function geo_bounds($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
238
    {
239
        throw new NotImplementedException();
240
    }
241
242
    /**
243
     * top hits aggregation.
244
     *
245
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
246
     *
247
     * @param string $name
248
     *
249
     * @return TopHits
250
     */
251
    public function top_hits(string $name): TopHits
252
    {
253
        return new TopHits($name);
254
    }
255
256
    /**
257
     * scripted metric aggregation.
258
     *
259
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html
260
     *
261
     * @param string      $name
262
     * @param string|null $initScript
263
     * @param string|null $mapScript
264
     * @param string|null $combineScript
265
     * @param string|null $reduceScript
266
     *
267
     * @return ScriptedMetric
268
     */
269
    public function scripted_metric(
270
        string $name,
271
        string $initScript = null,
272
        string $mapScript = null,
273
        string $combineScript = null,
274
        string $reduceScript = null
275
    ): ScriptedMetric {
276
        return new ScriptedMetric($name, $initScript, $mapScript, $combineScript, $reduceScript);
277
    }
278
279
    /**
280
     * global aggregation.
281
     *
282
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html
283
     *
284
     * @param string $name
285
     *
286
     * @return GlobalAggregation
287
     */
288
    public function global_agg(string $name): GlobalAggregation
289
    {
290
        return new GlobalAggregation($name);
291
    }
292
293
    /**
294
     * filter aggregation.
295
     *
296
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
297
     *
298
     * @param string        $name
299
     * @param AbstractQuery $filter
300
     *
301
     * @return Filter
302
     */
303
    public function filter(string $name, AbstractQuery $filter = null): Filter
304
    {
305
        return new Filter($name, $filter);
306
    }
307
308
    /**
309
     * filters aggregation.
310
     *
311
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html
312
     *
313
     * @param string $name
314
     *
315
     * @return Filters
316
     */
317
    public function filters(string $name): Filters
318
    {
319
        return new Filters($name);
320
    }
321
322
    /**
323
     * missing aggregation.
324
     *
325
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html
326
     *
327
     * @param string $name
328
     * @param string $field
329
     *
330
     * @return Missing
331
     */
332
    public function missing(string $name, string $field): Missing
333
    {
334
        return new Missing($name, $field);
335
    }
336
337
    /**
338
     * nested aggregation.
339
     *
340
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html
341
     *
342
     * @param string $name
343
     * @param string $path the nested path for this aggregation
344
     *
345
     * @return Nested
346
     */
347
    public function nested(string $name, string $path): Nested
348
    {
349
        return new Nested($name, $path);
350
    }
351
352
    /**
353
     * reverse nested aggregation.
354
     *
355
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
356
     *
357
     * @param string $name The name of this aggregation
358
     * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
359
     *
360
     * @return ReverseNested
361
     */
362
    public function reverse_nested(string $name, string $path = null): ReverseNested
363
    {
364
        return new ReverseNested($name, $path);
365
    }
366
367
    /**
368
     * children aggregation.
369
     *
370
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
371
     *
372
     * @param string $name
373
     */
374
    public function children($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
375
    {
376
        throw new NotImplementedException();
377
    }
378
379
    /**
380
     * terms aggregation.
381
     *
382
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
383
     *
384
     * @param string $name
385
     *
386
     * @return Terms
387
     */
388
    public function terms(string $name): Terms
389
    {
390
        return new Terms($name);
391
    }
392
393
    /**
394
     * significant terms aggregation.
395
     *
396
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html
397
     *
398
     * @param string $name
399
     *
400
     * @return SignificantTerms
401
     */
402
    public function significant_terms(string $name): SignificantTerms
403
    {
404
        return new SignificantTerms($name);
405
    }
406
407
    /**
408
     * range aggregation.
409
     *
410
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html
411
     *
412
     * @param string $name
413
     *
414
     * @return Range
415
     */
416
    public function range(string $name): Range
417
    {
418
        return new Range($name);
419
    }
420
421
    /**
422
     * date range aggregation.
423
     *
424
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
425
     *
426
     * @param string $name
427
     *
428
     * @return DateRange
429
     */
430
    public function date_range(string $name): DateRange
431
    {
432
        return new DateRange($name);
433
    }
434
435
    /**
436
     * ipv4 range aggregation.
437
     *
438
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html
439
     *
440
     * @param string $name
441
     * @param string $field
442
     *
443
     * @return IpRange
444
     */
445
    public function ipv4_range(string $name, string $field): IpRange
446
    {
447
        return new IpRange($name, $field);
448
    }
449
450
    /**
451
     * histogram aggregation.
452
     *
453
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
454
     *
455
     * @param string $name     the name of this aggregation
456
     * @param string $field    the name of the field on which to perform the aggregation
457
     * @param int    $interval the interval by which documents will be bucketed
458
     *
459
     * @return Histogram
460
     */
461
    public function histogram(string $name, string $field, $interval): Histogram
462
    {
463
        return new Histogram($name, $field, $interval);
464
    }
465
466
    /**
467
     * date histogram aggregation.
468
     *
469
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
470
     *
471
     * @param string     $name     the name of this aggregation
472
     * @param string     $field    the name of the field on which to perform the aggregation
473
     * @param int|string $interval the interval by which documents will be bucketed
474
     *
475
     * @return DateHistogram
476
     */
477
    public function date_histogram(string $name, string $field, $interval): DateHistogram
478
    {
479
        return new DateHistogram($name, $field, $interval);
480
    }
481
482
    /**
483
     * geo distance aggregation.
484
     *
485
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html
486
     *
487
     * @param string       $name   the name if this aggregation
488
     * @param string       $field  the field on which to perform this aggregation
489
     * @param string|array $origin the point from which distances will be calculated
490
     *
491
     * @return GeoDistance
492
     */
493
    public function geo_distance(string $name, string $field, $origin): GeoDistance
494
    {
495
        return new GeoDistance($name, $field, $origin);
496
    }
497
498
    /**
499
     * geohash grid aggregation.
500
     *
501
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html
502
     *
503
     * @param string $name  the name of this aggregation
504
     * @param string $field the field on which to perform this aggregation
505
     *
506
     * @return GeohashGrid
507
     */
508
    public function geohash_grid(string $name, string $field): GeohashGrid
509
    {
510
        return new GeohashGrid($name, $field);
511
    }
512
513
    /**
514
     * bucket script aggregation.
515
     *
516
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
517
     *
518
     * @param string      $name
519
     * @param array|null  $bucketsPath
520
     * @param string|null $script
521
     *
522
     * @return BucketScript
523
     */
524
    public function bucket_script(string $name, array $bucketsPath = null, string $script = null): BucketScript
525
    {
526
        return new BucketScript($name, $bucketsPath, $script);
527
    }
528
529
    /**
530
     * serial diff aggregation.
531
     *
532
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html
533
     *
534
     * @param string      $name
535
     * @param string|null $bucketsPath
536
     *
537
     * @return SerialDiff
538
     */
539
    public function serial_diff(string $name, string $bucketsPath = null): SerialDiff
540
    {
541
        return new SerialDiff($name, $bucketsPath);
542
    }
543
544
    /**
545
     * adjacency matrix aggregation.
546
     *
547
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html
548
     *
549
     * @param string $name
550
     *
551
     * @return AdjacencyMatrix
552
     */
553
    public function adjacency_matrix(string $name): AdjacencyMatrix
554
    {
555
        return new AdjacencyMatrix($name);
556
    }
557
558
    /** sampler aggregation.
559
     *
560
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html
561
     *
562
     * @param string $name
563
     *
564
     * @return Sampler
565
     */
566
    public function sampler($name): Sampler
567
    {
568
        return new Sampler($name);
569
    }
570
}
571