Completed
Push — master ( cdf882...92ebd2 )
by Nicolas
02:36
created

Aggregation::min()   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\DateHistogram;
11
use Elastica\Aggregation\DateRange;
12
use Elastica\Aggregation\DiversifiedSampler;
13
use Elastica\Aggregation\ExtendedStats;
14
use Elastica\Aggregation\Filter;
15
use Elastica\Aggregation\Filters;
16
use Elastica\Aggregation\GeoDistance;
17
use Elastica\Aggregation\GeohashGrid;
18
use Elastica\Aggregation\GlobalAggregation;
19
use Elastica\Aggregation\Histogram;
20
use Elastica\Aggregation\IpRange;
21
use Elastica\Aggregation\Max;
22
use Elastica\Aggregation\Min;
23
use Elastica\Aggregation\Missing;
24
use Elastica\Aggregation\Nested;
25
use Elastica\Aggregation\Percentiles;
26
use Elastica\Aggregation\PercentilesBucket;
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
     * percentiles_bucket aggregation.
165
     *
166
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html
167
     *
168
     * @param string $name        the name of this aggregation
169
     * @param string $bucketsPath the field on which to perform this aggregation
170
     */
171
    public function percentiles_bucket(string $name, ?string $bucketsPath = null): PercentilesBucket
172
    {
173
        return new PercentilesBucket($name, $bucketsPath);
174
    }
175
176
    /**
177
     * cardinality aggregation.
178
     *
179
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
180
     */
181
    public function cardinality(string $name): Cardinality
182
    {
183
        return new Cardinality($name);
184
    }
185
186
    /**
187
     * geo bounds aggregation.
188
     *
189
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html
190
     *
191
     * @param string $name
192
     */
193
    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...
194
    {
195
        throw new NotImplementedException();
196
    }
197
198
    /**
199
     * top hits aggregation.
200
     *
201
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
202
     */
203
    public function top_hits(string $name): TopHits
204
    {
205
        return new TopHits($name);
206
    }
207
208
    /**
209
     * scripted metric aggregation.
210
     *
211
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html
212
     */
213
    public function scripted_metric(
214
        string $name,
215
        ?string $initScript = null,
216
        ?string $mapScript = null,
217
        ?string $combineScript = null,
218
        ?string $reduceScript = null
219
    ): ScriptedMetric {
220
        return new ScriptedMetric($name, $initScript, $mapScript, $combineScript, $reduceScript);
221
    }
222
223
    /**
224
     * global aggregation.
225
     *
226
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html
227
     */
228
    public function global_agg(string $name): GlobalAggregation
229
    {
230
        return new GlobalAggregation($name);
231
    }
232
233
    /**
234
     * filter aggregation.
235
     *
236
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
237
     *
238
     * @param AbstractQuery $filter
239
     */
240
    public function filter(string $name, ?AbstractQuery $filter = null): Filter
241
    {
242
        return new Filter($name, $filter);
243
    }
244
245
    /**
246
     * filters aggregation.
247
     *
248
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html
249
     */
250
    public function filters(string $name): Filters
251
    {
252
        return new Filters($name);
253
    }
254
255
    /**
256
     * missing aggregation.
257
     *
258
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html
259
     */
260
    public function missing(string $name, string $field): Missing
261
    {
262
        return new Missing($name, $field);
263
    }
264
265
    /**
266
     * nested aggregation.
267
     *
268
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html
269
     *
270
     * @param string $path the nested path for this aggregation
271
     */
272
    public function nested(string $name, string $path): Nested
273
    {
274
        return new Nested($name, $path);
275
    }
276
277
    /**
278
     * reverse nested aggregation.
279
     *
280
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
281
     *
282
     * @param string $name The name of this aggregation
283
     * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
284
     */
285
    public function reverse_nested(string $name, ?string $path = null): ReverseNested
286
    {
287
        return new ReverseNested($name, $path);
288
    }
289
290
    /**
291
     * terms aggregation.
292
     *
293
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
294
     */
295
    public function terms(string $name): Terms
296
    {
297
        return new Terms($name);
298
    }
299
300
    /**
301
     * significant terms aggregation.
302
     *
303
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html
304
     */
305
    public function significant_terms(string $name): SignificantTerms
306
    {
307
        return new SignificantTerms($name);
308
    }
309
310
    /**
311
     * range aggregation.
312
     *
313
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html
314
     */
315
    public function range(string $name): Range
316
    {
317
        return new Range($name);
318
    }
319
320
    /**
321
     * date range aggregation.
322
     *
323
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
324
     */
325
    public function date_range(string $name): DateRange
326
    {
327
        return new DateRange($name);
328
    }
329
330
    /**
331
     * ipv4 range aggregation.
332
     *
333
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html
334
     */
335
    public function ipv4_range(string $name, string $field): IpRange
336
    {
337
        return new IpRange($name, $field);
338
    }
339
340
    /**
341
     * histogram aggregation.
342
     *
343
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
344
     *
345
     * @param string $name     the name of this aggregation
346
     * @param string $field    the name of the field on which to perform the aggregation
347
     * @param int    $interval the interval by which documents will be bucketed
348
     */
349
    public function histogram(string $name, string $field, $interval): Histogram
350
    {
351
        return new Histogram($name, $field, $interval);
352
    }
353
354
    /**
355
     * date histogram aggregation.
356
     *
357
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-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|string $interval the interval by which documents will be bucketed
362
     */
363
    public function date_histogram(string $name, string $field, $interval): DateHistogram
364
    {
365
        return new DateHistogram($name, $field, $interval);
366
    }
367
368
    /**
369
     * geo distance aggregation.
370
     *
371
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html
372
     *
373
     * @param string       $name   the name if this aggregation
374
     * @param string       $field  the field on which to perform this aggregation
375
     * @param array|string $origin the point from which distances will be calculated
376
     */
377
    public function geo_distance(string $name, string $field, $origin): GeoDistance
378
    {
379
        return new GeoDistance($name, $field, $origin);
380
    }
381
382
    /**
383
     * geohash grid aggregation.
384
     *
385
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html
386
     *
387
     * @param string $name  the name of this aggregation
388
     * @param string $field the field on which to perform this aggregation
389
     */
390
    public function geohash_grid(string $name, string $field): GeohashGrid
391
    {
392
        return new GeohashGrid($name, $field);
393
    }
394
395
    /**
396
     * bucket script aggregation.
397
     *
398
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
399
     */
400
    public function bucket_script(string $name, ?array $bucketsPath = null, ?string $script = null): BucketScript
401
    {
402
        return new BucketScript($name, $bucketsPath, $script);
403
    }
404
405
    /**
406
     * serial diff aggregation.
407
     *
408
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html
409
     */
410
    public function serial_diff(string $name, ?string $bucketsPath = null): SerialDiff
411
    {
412
        return new SerialDiff($name, $bucketsPath);
413
    }
414
415
    /**
416
     * adjacency matrix aggregation.
417
     *
418
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html
419
     */
420
    public function adjacency_matrix(string $name): AdjacencyMatrix
421
    {
422
        return new AdjacencyMatrix($name);
423
    }
424
425
    /** sampler aggregation.
426
     *
427
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html
428
     *
429
     * @param string $name
430
     */
431
    public function sampler($name): Sampler
432
    {
433
        return new Sampler($name);
434
    }
435
436
    /**
437
     * diversified sampler aggregation.
438
     *
439
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html
440
     */
441
    public function diversified_sampler(string $name): DiversifiedSampler
442
    {
443
        return new DiversifiedSampler($name);
444
    }
445
}
446