Completed
Push — master ( 6bb06a...788711 )
by
unknown
04:18 queued 01:49
created

Aggregation::global()   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\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\GlobalAggregation;
20
use Elastica\Aggregation\Histogram;
21
use Elastica\Aggregation\IpRange;
22
use Elastica\Aggregation\Max;
23
use Elastica\Aggregation\Min;
24
use Elastica\Aggregation\Missing;
25
use Elastica\Aggregation\Nested;
26
use Elastica\Aggregation\Percentiles;
27
use Elastica\Aggregation\PercentilesBucket;
28
use Elastica\Aggregation\Range;
29
use Elastica\Aggregation\ReverseNested;
30
use Elastica\Aggregation\Sampler;
31
use Elastica\Aggregation\ScriptedMetric;
32
use Elastica\Aggregation\SerialDiff;
33
use Elastica\Aggregation\SignificantTerms;
34
use Elastica\Aggregation\Stats;
35
use Elastica\Aggregation\Sum;
36
use Elastica\Aggregation\SumBucket;
37
use Elastica\Aggregation\Terms;
38
use Elastica\Aggregation\TopHits;
39
use Elastica\Aggregation\ValueCount;
40
use Elastica\Aggregation\WeightedAvg;
41
use Elastica\Exception\NotImplementedException;
42
use Elastica\Query\AbstractQuery;
43
use Elastica\QueryBuilder\DSL;
44
45
/**
46
 * Elasticsearch aggregation DSL.
47
 *
48
 * @author Manuel Andreo Garcia <[email protected]>
49
 *
50
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html
51
 */
52
class Aggregation implements DSL
53
{
54
    /**
55
     * must return type for QueryBuilder usage.
56
     */
57
    public function getType(): string
58
    {
59
        return DSL::TYPE_AGGREGATION;
60
    }
61
62
    /**
63
     * min aggregation.
64
     *
65
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html
66
     */
67
    public function min(string $name): Min
68
    {
69
        return new Min($name);
70
    }
71
72
    /**
73
     * max aggregation.
74
     *
75
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
76
     */
77
    public function max(string $name): Max
78
    {
79
        return new Max($name);
80
    }
81
82
    /**
83
     * sum aggregation.
84
     *
85
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html
86
     */
87
    public function sum(string $name): Sum
88
    {
89
        return new Sum($name);
90
    }
91
92
    /**
93
     * sum bucket aggregation.
94
     *
95
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html
96
     */
97
    public function sum_bucket(string $name, ?string $bucketsPath = null): SumBucket
98
    {
99
        return new SumBucket($name, $bucketsPath);
100
    }
101
102
    /**
103
     * avg aggregation.
104
     *
105
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
106
     */
107
    public function avg(string $name): Avg
108
    {
109
        return new Avg($name);
110
    }
111
112
    /**
113
     * avg bucket aggregation.
114
     *
115
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
116
     */
117
    public function avg_bucket(string $name, ?string $bucketsPath = null): AvgBucket
118
    {
119
        return new AvgBucket($name, $bucketsPath);
120
    }
121
122
    /**
123
     * stats aggregation.
124
     *
125
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
126
     */
127
    public function stats(string $name): Stats
128
    {
129
        return new Stats($name);
130
    }
131
132
    /**
133
     * extended stats aggregation.
134
     *
135
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html
136
     */
137
    public function extended_stats(string $name): ExtendedStats
138
    {
139
        return new ExtendedStats($name);
140
    }
141
142
    /**
143
     * value count aggregation.
144
     *
145
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html
146
     */
147
    public function value_count(string $name, string $field): ValueCount
148
    {
149
        return new ValueCount($name, $field);
150
    }
151
152
    /**
153
     * percentiles aggregation.
154
     *
155
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
156
     *
157
     * @param string $name  the name of this aggregation
158
     * @param string $field the field on which to perform this aggregation
159
     */
160
    public function percentiles(string $name, ?string $field = null): Percentiles
161
    {
162
        return new Percentiles($name, $field);
163
    }
164
165
    /**
166
     * percentiles_bucket aggregation.
167
     *
168
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html
169
     *
170
     * @param string $name        the name of this aggregation
171
     * @param string $bucketsPath the field on which to perform this aggregation
172
     */
173
    public function percentiles_bucket(string $name, ?string $bucketsPath = null): PercentilesBucket
174
    {
175
        return new PercentilesBucket($name, $bucketsPath);
176
    }
177
178
    /**
179
     * cardinality aggregation.
180
     *
181
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
182
     */
183
    public function cardinality(string $name): Cardinality
184
    {
185
        return new Cardinality($name);
186
    }
187
188
    /**
189
     * geo bounds aggregation.
190
     *
191
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html
192
     *
193
     * @param string $name
194
     */
195
    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...
196
    {
197
        throw new NotImplementedException();
198
    }
199
200
    /**
201
     * top hits aggregation.
202
     *
203
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
204
     */
205
    public function top_hits(string $name): TopHits
206
    {
207
        return new TopHits($name);
208
    }
209
210
    /**
211
     * scripted metric aggregation.
212
     *
213
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html
214
     */
215
    public function scripted_metric(
216
        string $name,
217
        ?string $initScript = null,
218
        ?string $mapScript = null,
219
        ?string $combineScript = null,
220
        ?string $reduceScript = null
221
    ): ScriptedMetric {
222
        return new ScriptedMetric($name, $initScript, $mapScript, $combineScript, $reduceScript);
223
    }
224
225
    /**
226
     * global aggregation.
227
     *
228
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html
229
     */
230
    public function global(string $name): GlobalAggregation
231
    {
232
        return new GlobalAggregation($name);
233
    }
234
235
    /**
236
     * @deprecated since Elastica 7.0.1, use the "global()" method instead.
237
     */
238
    public function global_agg(string $name): GlobalAggregation
239
    {
240
        @\trigger_error(\sprintf('The "%s()" method is deprecated since Elastica 7.0.1, use global() instead.', __METHOD__), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
241
242
        return $this->global($name);
243
    }
244
245
    /**
246
     * filter aggregation.
247
     *
248
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
249
     *
250
     * @param AbstractQuery $filter
251
     */
252
    public function filter(string $name, ?AbstractQuery $filter = null): Filter
253
    {
254
        return new Filter($name, $filter);
255
    }
256
257
    /**
258
     * filters aggregation.
259
     *
260
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html
261
     */
262
    public function filters(string $name): Filters
263
    {
264
        return new Filters($name);
265
    }
266
267
    /**
268
     * missing aggregation.
269
     *
270
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html
271
     */
272
    public function missing(string $name, string $field): Missing
273
    {
274
        return new Missing($name, $field);
275
    }
276
277
    /**
278
     * nested aggregation.
279
     *
280
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html
281
     *
282
     * @param string $path the nested path for this aggregation
283
     */
284
    public function nested(string $name, string $path): Nested
285
    {
286
        return new Nested($name, $path);
287
    }
288
289
    /**
290
     * reverse nested aggregation.
291
     *
292
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
293
     *
294
     * @param string $name The name of this aggregation
295
     * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
296
     */
297
    public function reverse_nested(string $name, ?string $path = null): ReverseNested
298
    {
299
        return new ReverseNested($name, $path);
300
    }
301
302
    /**
303
     * terms aggregation.
304
     *
305
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
306
     */
307
    public function terms(string $name): Terms
308
    {
309
        return new Terms($name);
310
    }
311
312
    /**
313
     * significant terms aggregation.
314
     *
315
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html
316
     */
317
    public function significant_terms(string $name): SignificantTerms
318
    {
319
        return new SignificantTerms($name);
320
    }
321
322
    /**
323
     * range aggregation.
324
     *
325
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html
326
     */
327
    public function range(string $name): Range
328
    {
329
        return new Range($name);
330
    }
331
332
    /**
333
     * date range aggregation.
334
     *
335
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
336
     */
337
    public function date_range(string $name): DateRange
338
    {
339
        return new DateRange($name);
340
    }
341
342
    /**
343
     * ipv4 range aggregation.
344
     *
345
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html
346
     */
347
    public function ipv4_range(string $name, string $field): IpRange
348
    {
349
        return new IpRange($name, $field);
350
    }
351
352
    /**
353
     * histogram aggregation.
354
     *
355
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
356
     *
357
     * @param string $name     the name of this aggregation
358
     * @param string $field    the name of the field on which to perform the aggregation
359
     * @param int    $interval the interval by which documents will be bucketed
360
     */
361
    public function histogram(string $name, string $field, $interval): Histogram
362
    {
363
        return new Histogram($name, $field, $interval);
364
    }
365
366
    /**
367
     * date histogram aggregation.
368
     *
369
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
370
     *
371
     * @param string     $name     the name of this aggregation
372
     * @param string     $field    the name of the field on which to perform the aggregation
373
     * @param int|string $interval the interval by which documents will be bucketed
374
     */
375
    public function date_histogram(string $name, string $field, $interval): DateHistogram
376
    {
377
        return new DateHistogram($name, $field, $interval);
378
    }
379
380
    /**
381
     * geo distance aggregation.
382
     *
383
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html
384
     *
385
     * @param string       $name   the name if this aggregation
386
     * @param string       $field  the field on which to perform this aggregation
387
     * @param array|string $origin the point from which distances will be calculated
388
     */
389
    public function geo_distance(string $name, string $field, $origin): GeoDistance
390
    {
391
        return new GeoDistance($name, $field, $origin);
392
    }
393
394
    /**
395
     * geohash grid aggregation.
396
     *
397
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html
398
     *
399
     * @param string $name  the name of this aggregation
400
     * @param string $field the field on which to perform this aggregation
401
     */
402
    public function geohash_grid(string $name, string $field): GeohashGrid
403
    {
404
        return new GeohashGrid($name, $field);
405
    }
406
407
    /**
408
     * bucket script aggregation.
409
     *
410
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
411
     */
412
    public function bucket_script(string $name, ?array $bucketsPath = null, ?string $script = null): BucketScript
413
    {
414
        return new BucketScript($name, $bucketsPath, $script);
415
    }
416
417
    /**
418
     * serial diff aggregation.
419
     *
420
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html
421
     */
422
    public function serial_diff(string $name, ?string $bucketsPath = null): SerialDiff
423
    {
424
        return new SerialDiff($name, $bucketsPath);
425
    }
426
427
    /**
428
     * adjacency matrix aggregation.
429
     *
430
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html
431
     */
432
    public function adjacency_matrix(string $name): AdjacencyMatrix
433
    {
434
        return new AdjacencyMatrix($name);
435
    }
436
437
    /**
438
     * sampler aggregation.
439
     *
440
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html
441
     */
442
    public function sampler(string $name): Sampler
443
    {
444
        return new Sampler($name);
445
    }
446
447
    /**
448
     * diversified sampler aggregation.
449
     *
450
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html
451
     */
452
    public function diversified_sampler(string $name): DiversifiedSampler
453
    {
454
        return new DiversifiedSampler($name);
455
    }
456
457
    /**
458
     * weighted avg aggregation.
459
     *
460
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html
461
     */
462
    public function weighted_avg(string $name): WeightedAvg
463
    {
464
        return new WeightedAvg($name);
465
    }
466
467
    /**
468
     * composite aggregation.
469
     *
470
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html
471
     */
472
    public function composite(string $name): Composite
473
    {
474
        return new Composite($name);
475
    }
476
}
477