Completed
Pull Request — master (#1804)
by Pierre
02:49
created

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