Completed
Push — master ( 9ac813...50c323 )
by
unknown
03:09 queued 45s
created

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