Completed
Push — master ( 8de1db...2e7705 )
by Nicolas
02:22
created

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