Completed
Push — master ( 54d8cb...f982ca )
by Ema
01:58
created

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