Completed
Push — master ( 542835...98e5e9 )
by Nicolas
02:13
created

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