Completed
Push — master ( f8a88d...dd8807 )
by Nicolas
02:45
created

Aggregation::normalize()   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 3
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\Composite;
11
use Elastica\Aggregation\DateHistogram;
12
use Elastica\Aggregation\DateRange;
13
use Elastica\Aggregation\DiversifiedSampler;
14
use Elastica\Aggregation\ExtendedStats;
15
use Elastica\Aggregation\Filter;
16
use Elastica\Aggregation\Filters;
17
use Elastica\Aggregation\GeoDistance;
18
use Elastica\Aggregation\GeohashGrid;
19
use Elastica\Aggregation\GeotileGridAggregation;
20
use Elastica\Aggregation\GlobalAggregation;
21
use Elastica\Aggregation\Histogram;
22
use Elastica\Aggregation\IpRange;
23
use Elastica\Aggregation\Max;
24
use Elastica\Aggregation\Min;
25
use Elastica\Aggregation\Missing;
26
use Elastica\Aggregation\Nested;
27
use Elastica\Aggregation\NormalizeAggregation;
28
use Elastica\Aggregation\Percentiles;
29
use Elastica\Aggregation\PercentilesBucket;
30
use Elastica\Aggregation\Range;
31
use Elastica\Aggregation\ReverseNested;
32
use Elastica\Aggregation\Sampler;
33
use Elastica\Aggregation\ScriptedMetric;
34
use Elastica\Aggregation\SerialDiff;
35
use Elastica\Aggregation\SignificantTerms;
36
use Elastica\Aggregation\Stats;
37
use Elastica\Aggregation\Sum;
38
use Elastica\Aggregation\SumBucket;
39
use Elastica\Aggregation\Terms;
40
use Elastica\Aggregation\TopHits;
41
use Elastica\Aggregation\ValueCount;
42
use Elastica\Aggregation\WeightedAvg;
43
use Elastica\Exception\NotImplementedException;
44
use Elastica\Query\AbstractQuery;
45
use Elastica\QueryBuilder\DSL;
46
47
/**
48
 * Elasticsearch aggregation DSL.
49
 *
50
 * @author Manuel Andreo Garcia <[email protected]>
51
 *
52
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html
53
 */
54
class Aggregation implements DSL
55
{
56
    /**
57
     * must return type for QueryBuilder usage.
58
     */
59
    public function getType(): string
60
    {
61
        return DSL::TYPE_AGGREGATION;
62
    }
63
64
    /**
65
     * min aggregation.
66
     *
67
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html
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
    public function max(string $name): Max
80
    {
81
        return new Max($name);
82
    }
83
84
    /**
85
     * sum aggregation.
86
     *
87
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html
88
     */
89
    public function sum(string $name): Sum
90
    {
91
        return new Sum($name);
92
    }
93
94
    /**
95
     * sum bucket aggregation.
96
     *
97
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html
98
     */
99
    public function sum_bucket(string $name, ?string $bucketsPath = null): SumBucket
100
    {
101
        return new SumBucket($name, $bucketsPath);
102
    }
103
104
    /**
105
     * avg aggregation.
106
     *
107
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
108
     */
109
    public function avg(string $name): Avg
110
    {
111
        return new Avg($name);
112
    }
113
114
    /**
115
     * avg bucket aggregation.
116
     *
117
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
118
     */
119
    public function avg_bucket(string $name, ?string $bucketsPath = null): AvgBucket
120
    {
121
        return new AvgBucket($name, $bucketsPath);
122
    }
123
124
    /**
125
     * stats aggregation.
126
     *
127
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
128
     */
129
    public function stats(string $name): Stats
130
    {
131
        return new Stats($name);
132
    }
133
134
    /**
135
     * extended stats aggregation.
136
     *
137
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html
138
     */
139
    public function extended_stats(string $name): ExtendedStats
140
    {
141
        return new ExtendedStats($name);
142
    }
143
144
    /**
145
     * value count aggregation.
146
     *
147
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html
148
     */
149
    public function value_count(string $name, string $field): ValueCount
150
    {
151
        return new ValueCount($name, $field);
152
    }
153
154
    /**
155
     * percentiles aggregation.
156
     *
157
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
158
     *
159
     * @param string $name  the name of this aggregation
160
     * @param string $field the field on which to perform this aggregation
161
     */
162
    public function percentiles(string $name, ?string $field = null): Percentiles
163
    {
164
        return new Percentiles($name, $field);
165
    }
166
167
    /**
168
     * percentiles_bucket aggregation.
169
     *
170
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html
171
     *
172
     * @param string $name        the name of this aggregation
173
     * @param string $bucketsPath the field on which to perform this aggregation
174
     */
175
    public function percentiles_bucket(string $name, ?string $bucketsPath = null): PercentilesBucket
176
    {
177
        return new PercentilesBucket($name, $bucketsPath);
178
    }
179
180
    /**
181
     * cardinality aggregation.
182
     *
183
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
184
     */
185
    public function cardinality(string $name): Cardinality
186
    {
187
        return new Cardinality($name);
188
    }
189
190
    /**
191
     * geo bounds aggregation.
192
     *
193
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html
194
     *
195
     * @param string $name
196
     */
197
    public function geo_bounds($name): void
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...
198
    {
199
        throw new NotImplementedException();
200
    }
201
202
    /**
203
     * top hits aggregation.
204
     *
205
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
206
     */
207
    public function top_hits(string $name): TopHits
208
    {
209
        return new TopHits($name);
210
    }
211
212
    /**
213
     * scripted metric aggregation.
214
     *
215
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html
216
     */
217
    public function scripted_metric(
218
        string $name,
219
        ?string $initScript = null,
220
        ?string $mapScript = null,
221
        ?string $combineScript = null,
222
        ?string $reduceScript = null
223
    ): ScriptedMetric {
224
        return new ScriptedMetric($name, $initScript, $mapScript, $combineScript, $reduceScript);
225
    }
226
227
    /**
228
     * global aggregation.
229
     *
230
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html
231
     */
232
    public function global(string $name): GlobalAggregation
233
    {
234
        return new GlobalAggregation($name);
235
    }
236
237
    /**
238
     * @deprecated since version 7.1.0, use the "global()" method instead.
239
     */
240
    public function global_agg(string $name): GlobalAggregation
241
    {
242
        trigger_deprecation('ruflin/elastica', '7.1.0', 'The "%s()" method is deprecated, use "global()" instead. It will be removed in 8.0.', __METHOD__);
243
244
        return $this->global($name);
245
    }
246
247
    /**
248
     * filter aggregation.
249
     *
250
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
251
     *
252
     * @param AbstractQuery $filter
253
     */
254
    public function filter(string $name, ?AbstractQuery $filter = null): Filter
255
    {
256
        return new Filter($name, $filter);
257
    }
258
259
    /**
260
     * filters aggregation.
261
     *
262
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html
263
     */
264
    public function filters(string $name): Filters
265
    {
266
        return new Filters($name);
267
    }
268
269
    /**
270
     * missing aggregation.
271
     *
272
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html
273
     */
274
    public function missing(string $name, string $field): Missing
275
    {
276
        return new Missing($name, $field);
277
    }
278
279
    /**
280
     * nested aggregation.
281
     *
282
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html
283
     *
284
     * @param string $path the nested path for this aggregation
285
     */
286
    public function nested(string $name, string $path): Nested
287
    {
288
        return new Nested($name, $path);
289
    }
290
291
    /**
292
     * reverse nested aggregation.
293
     *
294
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
295
     *
296
     * @param string $name The name of this aggregation
297
     * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
298
     */
299
    public function reverse_nested(string $name, ?string $path = null): ReverseNested
300
    {
301
        return new ReverseNested($name, $path);
302
    }
303
304
    /**
305
     * terms aggregation.
306
     *
307
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
308
     */
309
    public function terms(string $name): Terms
310
    {
311
        return new Terms($name);
312
    }
313
314
    /**
315
     * significant terms aggregation.
316
     *
317
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html
318
     */
319
    public function significant_terms(string $name): SignificantTerms
320
    {
321
        return new SignificantTerms($name);
322
    }
323
324
    /**
325
     * range aggregation.
326
     *
327
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html
328
     */
329
    public function range(string $name): Range
330
    {
331
        return new Range($name);
332
    }
333
334
    /**
335
     * date range aggregation.
336
     *
337
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
338
     */
339
    public function date_range(string $name): DateRange
340
    {
341
        return new DateRange($name);
342
    }
343
344
    /**
345
     * ipv4 range aggregation.
346
     *
347
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html
348
     */
349
    public function ipv4_range(string $name, string $field): IpRange
350
    {
351
        return new IpRange($name, $field);
352
    }
353
354
    /**
355
     * histogram aggregation.
356
     *
357
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
358
     *
359
     * @param string $name     the name of this aggregation
360
     * @param string $field    the name of the field on which to perform the aggregation
361
     * @param int    $interval the interval by which documents will be bucketed
362
     */
363
    public function histogram(string $name, string $field, $interval): Histogram
364
    {
365
        return new Histogram($name, $field, $interval);
366
    }
367
368
    /**
369
     * date histogram aggregation.
370
     *
371
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
372
     *
373
     * @param string     $name     the name of this aggregation
374
     * @param string     $field    the name of the field on which to perform the aggregation
375
     * @param int|string $interval the interval by which documents will be bucketed
376
     */
377
    public function date_histogram(string $name, string $field, $interval): DateHistogram
378
    {
379
        return new DateHistogram($name, $field, $interval);
380
    }
381
382
    /**
383
     * geo distance aggregation.
384
     *
385
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html
386
     *
387
     * @param string       $name   the name if this aggregation
388
     * @param string       $field  the field on which to perform this aggregation
389
     * @param array|string $origin the point from which distances will be calculated
390
     */
391
    public function geo_distance(string $name, string $field, $origin): GeoDistance
392
    {
393
        return new GeoDistance($name, $field, $origin);
394
    }
395
396
    /**
397
     * geohash grid aggregation.
398
     *
399
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html
400
     *
401
     * @param string $name  the name of this aggregation
402
     * @param string $field the field on which to perform this aggregation
403
     */
404
    public function geohash_grid(string $name, string $field): GeohashGrid
405
    {
406
        return new GeohashGrid($name, $field);
407
    }
408
409
    /**
410
     * geotile grid aggregation.
411
     *
412
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geotilegrid-aggregation.html
413
     *
414
     * @param string $name  the name of this aggregation
415
     * @param string $field the field on which to perform this aggregation
416
     */
417
    public function geotile_grid(string $name, string $field): GeotileGridAggregation
418
    {
419
        return new GeotileGridAggregation($name, $field);
420
    }
421
422
    /**
423
     * bucket script aggregation.
424
     *
425
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
426
     */
427
    public function bucket_script(string $name, ?array $bucketsPath = null, ?string $script = null): BucketScript
428
    {
429
        return new BucketScript($name, $bucketsPath, $script);
430
    }
431
432
    /**
433
     * serial diff aggregation.
434
     *
435
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html
436
     */
437
    public function serial_diff(string $name, ?string $bucketsPath = null): SerialDiff
438
    {
439
        return new SerialDiff($name, $bucketsPath);
440
    }
441
442
    /**
443
     * adjacency matrix aggregation.
444
     *
445
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html
446
     */
447
    public function adjacency_matrix(string $name): AdjacencyMatrix
448
    {
449
        return new AdjacencyMatrix($name);
450
    }
451
452
    /**
453
     * sampler aggregation.
454
     *
455
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html
456
     */
457
    public function sampler(string $name): Sampler
458
    {
459
        return new Sampler($name);
460
    }
461
462
    /**
463
     * diversified sampler aggregation.
464
     *
465
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html
466
     */
467
    public function diversified_sampler(string $name): DiversifiedSampler
468
    {
469
        return new DiversifiedSampler($name);
470
    }
471
472
    /**
473
     * weighted avg aggregation.
474
     *
475
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html
476
     */
477
    public function weighted_avg(string $name): WeightedAvg
478
    {
479
        return new WeightedAvg($name);
480
    }
481
482
    /**
483
     * composite aggregation.
484
     *
485
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html
486
     */
487
    public function composite(string $name): Composite
488
    {
489
        return new Composite($name);
490
    }
491
492
    /**
493
     * normalize aggregation.
494
     *
495
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-normalize-aggregation.html
496
     */
497
    public function normalize(string $name, ?string $bucketsPath = null, ?string $method = null): NormalizeAggregation
498
    {
499
        return new NormalizeAggregation($name, $bucketsPath, $method);
500
    }
501
}
502