|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
namespace Triadev\Leopard\Business\Dsl\Aggregation; |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\AvgAggregation; |
|
5
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\CardinalityAggregation; |
|
6
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\ExtendedStatsAggregation; |
|
7
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\GeoBoundsAggregation; |
|
8
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\GeoCentroidAggregation; |
|
9
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\MaxAggregation; |
|
10
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\MinAggregation; |
|
11
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\StatsAggregation; |
|
12
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\SumAggregation; |
|
13
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\TopHitsAggregation; |
|
14
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Metric\ValueCountAggregation; |
|
15
|
|
|
use ONGR\ElasticsearchDSL\BuilderInterface; |
|
16
|
|
|
|
|
17
|
|
|
class Metric extends Aggs |
|
|
|
|
|
|
18
|
|
|
{ |
|
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Avg |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $name |
|
|
|
|
|
|
23
|
|
|
* @param string|null $field |
|
|
|
|
|
|
24
|
|
|
* @param string|null $script |
|
|
|
|
|
|
25
|
|
|
* @return Metric |
|
|
|
|
|
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function avg(string $name, ?string $field = null, ?string $script = null) : Metric |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
2 |
|
$this->addAggregation(new AvgAggregation($name, $field, $script)); |
|
30
|
2 |
|
return $this; |
|
31
|
|
|
} |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Cardinality |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $name |
|
|
|
|
|
|
37
|
|
|
* @param string $field |
|
|
|
|
|
|
38
|
|
|
* @return Metric |
|
|
|
|
|
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function cardinality(string $name, string $field) : Metric |
|
41
|
|
|
{ |
|
42
|
1 |
|
$cardinality = new CardinalityAggregation($name); |
|
43
|
1 |
|
$cardinality->setField($field); |
|
44
|
|
|
|
|
45
|
1 |
|
$this->addAggregation($cardinality); |
|
46
|
1 |
|
return $this; |
|
47
|
|
|
} |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Extended stats |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $name |
|
|
|
|
|
|
53
|
|
|
* @param string $field |
|
|
|
|
|
|
54
|
|
|
* @param int|null $sigma |
|
|
|
|
|
|
55
|
|
|
* @param string|null $script |
|
|
|
|
|
|
56
|
|
|
* @return Metric |
|
|
|
|
|
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function extendedStats(string $name, string $field, ?int $sigma = null, ?string $script = null) : Metric |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
1 |
|
$this->addAggregation(new ExtendedStatsAggregation($name, $field, $sigma, $script)); |
|
61
|
1 |
|
return $this; |
|
62
|
|
|
} |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Geo bounds |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $name |
|
|
|
|
|
|
68
|
|
|
* @param string|null $field |
|
|
|
|
|
|
69
|
|
|
* @param bool $wrapLongitude |
|
|
|
|
|
|
70
|
|
|
* @return Metric |
|
|
|
|
|
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function geoBounds(string $name, ?string $field = null, bool $wrapLongitude = true) : Metric |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
1 |
|
$this->addAggregation(new GeoBoundsAggregation($name, $field, $wrapLongitude)); |
|
75
|
1 |
|
return $this; |
|
76
|
|
|
} |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Geo centroid |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $name |
|
|
|
|
|
|
82
|
|
|
* @param string|null $field |
|
|
|
|
|
|
83
|
|
|
* @return Metric |
|
|
|
|
|
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function geoCentroid(string $name, ?string $field = null) : Metric |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
1 |
|
$this->addAggregation(new GeoCentroidAggregation($name, $field)); |
|
88
|
1 |
|
return $this; |
|
89
|
|
|
} |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Max |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $name |
|
|
|
|
|
|
95
|
|
|
* @param string|null $field |
|
|
|
|
|
|
96
|
|
|
* @param string|null $script |
|
|
|
|
|
|
97
|
|
|
* @return Metric |
|
|
|
|
|
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function max(string $name, ?string $field = null, ?string $script = null) : Metric |
|
|
|
|
|
|
100
|
|
|
{ |
|
101
|
1 |
|
$this->addAggregation(new MaxAggregation($name, $field, $script)); |
|
102
|
1 |
|
return $this; |
|
103
|
|
|
} |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Min |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $name |
|
|
|
|
|
|
109
|
|
|
* @param string|null $field |
|
|
|
|
|
|
110
|
|
|
* @param string|null $script |
|
|
|
|
|
|
111
|
|
|
* @return Metric |
|
|
|
|
|
|
112
|
|
|
*/ |
|
113
|
1 |
|
public function min(string $name, ?string $field = null, ?string $script = null): Metric |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
1 |
|
$this->addAggregation(new MinAggregation($name, $field, $script)); |
|
116
|
1 |
|
return $this; |
|
117
|
|
|
} |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Stats |
|
121
|
|
|
* |
|
122
|
|
|
* @param string $name |
|
|
|
|
|
|
123
|
|
|
* @param string|null $field |
|
|
|
|
|
|
124
|
|
|
* @param string|null $script |
|
|
|
|
|
|
125
|
|
|
* @return Metric |
|
|
|
|
|
|
126
|
|
|
*/ |
|
127
|
1 |
|
public function stats(string $name, ?string $field = null, ?string $script = null): Metric |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
1 |
|
$this->addAggregation(new StatsAggregation($name, $field, $script)); |
|
130
|
1 |
|
return $this; |
|
131
|
|
|
} |
|
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Sum |
|
135
|
|
|
* |
|
136
|
|
|
* @param string $name |
|
|
|
|
|
|
137
|
|
|
* @param string|null $field |
|
|
|
|
|
|
138
|
|
|
* @param string|null $script |
|
|
|
|
|
|
139
|
|
|
* @return Metric |
|
|
|
|
|
|
140
|
|
|
*/ |
|
141
|
1 |
|
public function sum(string $name, ?string $field = null, ?string $script = null): Metric |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
1 |
|
$this->addAggregation(new SumAggregation($name, $field, $script)); |
|
144
|
1 |
|
return $this; |
|
145
|
|
|
} |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Top hits |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $name |
|
|
|
|
|
|
151
|
|
|
* @param int|null $size |
|
|
|
|
|
|
152
|
|
|
* @param int|null $from |
|
|
|
|
|
|
153
|
|
|
* @param BuilderInterface|null $sort |
|
|
|
|
|
|
154
|
|
|
* @return Metric |
|
|
|
|
|
|
155
|
|
|
*/ |
|
156
|
1 |
|
public function topHits(string $name, ?int $size = null, ?int $from = null, ?BuilderInterface $sort = null) : Metric |
|
|
|
|
|
|
157
|
|
|
{ |
|
158
|
1 |
|
$this->addAggregation(new TopHitsAggregation($name, $size, $from, $sort)); |
|
159
|
1 |
|
return $this; |
|
160
|
|
|
} |
|
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Value count |
|
164
|
|
|
* |
|
165
|
|
|
* @param string $name |
|
|
|
|
|
|
166
|
|
|
* @param string|null $field |
|
|
|
|
|
|
167
|
|
|
* @param string|null $script |
|
|
|
|
|
|
168
|
|
|
* @return Metric |
|
|
|
|
|
|
169
|
|
|
*/ |
|
170
|
1 |
|
public function valueCount(string $name, ?string $field = null, ?string $script = null): Metric |
|
|
|
|
|
|
171
|
|
|
{ |
|
172
|
1 |
|
$this->addAggregation(new ValueCountAggregation($name, $field, $script)); |
|
173
|
1 |
|
return $this; |
|
174
|
|
|
} |
|
|
|
|
|
|
175
|
|
|
} |
|
|
|
|
|
|
176
|
|
|
|