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