@@ -26,7 +26,9 @@ Let's look at a range of percentiles representing load time:
26
26
27
27
[source,js]
28
28
--------------------------------------------------
29
+ GET latency/data/_search
29
30
{
31
+ "size": 0,
30
32
"aggs" : {
31
33
"load_time_outlier" : {
32
34
"percentiles" : {
@@ -36,6 +38,8 @@ Let's look at a range of percentiles representing load time:
36
38
}
37
39
}
38
40
--------------------------------------------------
41
+ // CONSOLE
42
+ // TEST[setup:latency]
39
43
<1> The field `load_time` must be a numeric field
40
44
41
45
By default, the `percentile` metric will generate a range of
@@ -49,18 +53,19 @@ percentiles: `[ 1, 5, 25, 50, 75, 95, 99 ]`. The response will look like this:
49
53
"aggregations": {
50
54
"load_time_outlier": {
51
55
"values" : {
52
- "1.0": 15 ,
53
- "5.0": 20 ,
54
- "25.0": 23 ,
55
- "50.0": 25 ,
56
- "75.0": 29 ,
57
- "95.0": 60 ,
58
- "99.0": 150
56
+ "1.0": 9.9 ,
57
+ "5.0": 29.500000000000004 ,
58
+ "25.0": 167.5 ,
59
+ "50.0": 445.0 ,
60
+ "75.0": 722.5 ,
61
+ "95.0": 940.5 ,
62
+ "99.0": 980.1000000000001
59
63
}
60
64
}
61
65
}
62
66
}
63
67
--------------------------------------------------
68
+ // TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
64
69
65
70
As you can see, the aggregation will return a calculated value for each percentile
66
71
in the default range. If we assume response times are in milliseconds, it is
@@ -73,7 +78,9 @@ must be a value between 0-100 inclusive):
73
78
74
79
[source,js]
75
80
--------------------------------------------------
81
+ GET latency/data/_search
76
82
{
83
+ "size": 0,
77
84
"aggs" : {
78
85
"load_time_outlier" : {
79
86
"percentiles" : {
@@ -84,6 +91,8 @@ must be a value between 0-100 inclusive):
84
91
}
85
92
}
86
93
--------------------------------------------------
94
+ // CONSOLE
95
+ // TEST[setup:latency]
87
96
<1> Use the `percents` parameter to specify particular percentiles to calculate
88
97
89
98
==== Keyed Response
@@ -92,20 +101,21 @@ By default the `keyed` flag is set to `true` which associates a unique string ke
92
101
93
102
[source,js]
94
103
--------------------------------------------------
95
- POST bank/account /_search?size=0
104
+ GET latency/data /_search
96
105
{
106
+ "size": 0,
97
107
"aggs": {
98
- "balance_outlier ": {
108
+ "load_time_outlier ": {
99
109
"percentiles": {
100
- "field": "balance ",
110
+ "field": "load_time ",
101
111
"keyed": false
102
112
}
103
113
}
104
114
}
105
115
}
106
116
--------------------------------------------------
107
117
// CONSOLE
108
- // TEST[setup:bank ]
118
+ // TEST[setup:latency ]
109
119
110
120
Response:
111
121
@@ -115,49 +125,42 @@ Response:
115
125
...
116
126
117
127
"aggregations": {
118
- "balance_outlier ": {
128
+ "load_time_outlier ": {
119
129
"values": [
120
130
{
121
131
"key": 1.0,
122
- "value": 1462.8400000000001
132
+ "value": 9.9
123
133
},
124
134
{
125
135
"key": 5.0,
126
- "value": 3591.85
136
+ "value": 29.500000000000004
127
137
},
128
138
{
129
139
"key": 25.0,
130
- "value": 13709.333333333334
140
+ "value": 167.5
131
141
},
132
142
{
133
143
"key": 50.0,
134
- "value": 26020.11666666667
144
+ "value": 445.0
135
145
},
136
146
{
137
147
"key": 75.0,
138
- "value": 38139.648148148146
148
+ "value": 722.5
139
149
},
140
150
{
141
151
"key": 95.0,
142
- "value": 47551.549999999996
152
+ "value": 940.5
143
153
},
144
154
{
145
155
"key": 99.0,
146
- "value": 49339.16
156
+ "value": 980.1000000000001
147
157
}
148
158
]
149
159
}
150
160
}
151
161
}
152
162
--------------------------------------------------
153
163
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
154
- // TESTRESPONSE[s/1462.8400000000001/$body.aggregations.balance_outlier.values.0.value/]
155
- // TESTRESPONSE[s/3591.85/$body.aggregations.balance_outlier.values.1.value/]
156
- // TESTRESPONSE[s/13709.333333333334/$body.aggregations.balance_outlier.values.2.value/]
157
- // TESTRESPONSE[s/26020.11666666667/$body.aggregations.balance_outlier.values.3.value/]
158
- // TESTRESPONSE[s/38139.648148148146/$body.aggregations.balance_outlier.values.4.value/]
159
- // TESTRESPONSE[s/47551.549999999996/$body.aggregations.balance_outlier.values.5.value/]
160
- // TESTRESPONSE[s/49339.16/$body.aggregations.balance_outlier.values.6.value/]
161
164
162
165
==== Script
163
166
@@ -167,7 +170,9 @@ a script to convert them on-the-fly:
167
170
168
171
[source,js]
169
172
--------------------------------------------------
173
+ GET latency/data/_search
170
174
{
175
+ "size": 0,
171
176
"aggs" : {
172
177
"load_time_outlier" : {
173
178
"percentiles" : {
@@ -183,6 +188,9 @@ a script to convert them on-the-fly:
183
188
}
184
189
}
185
190
--------------------------------------------------
191
+ // CONSOLE
192
+ // TEST[setup:latency]
193
+
186
194
<1> The `field` parameter is replaced with a `script` parameter, which uses the
187
195
script to generate values which percentiles are calculated on
188
196
<2> Scripting supports parameterized input just like any other script
@@ -191,21 +199,25 @@ This will interpret the `script` parameter as an `inline` script with the `painl
191
199
192
200
[source,js]
193
201
--------------------------------------------------
202
+ GET latency/data/_search
194
203
{
204
+ "size": 0,
195
205
"aggs" : {
196
206
"load_time_outlier" : {
197
207
"percentiles" : {
198
208
"script" : {
199
209
"id": "my_script",
200
- "params" : {
201
- "timeUnit" : 1000
210
+ "params": {
211
+ "field": "load_time"
202
212
}
203
213
}
204
214
}
205
215
}
206
216
}
207
217
}
208
218
--------------------------------------------------
219
+ // CONSOLE
220
+ // TEST[setup:latency,stored_example_script]
209
221
210
222
[[search-aggregations-metrics-percentile-aggregation-approximation]]
211
223
==== Percentiles are (usually) approximate
@@ -252,7 +264,9 @@ This balance can be controlled using a `compression` parameter:
252
264
253
265
[source,js]
254
266
--------------------------------------------------
267
+ GET latency/data/_search
255
268
{
269
+ "size": 0,
256
270
"aggs" : {
257
271
"load_time_outlier" : {
258
272
"percentiles" : {
@@ -265,6 +279,9 @@ This balance can be controlled using a `compression` parameter:
265
279
}
266
280
}
267
281
--------------------------------------------------
282
+ // CONSOLE
283
+ // TEST[setup:latency]
284
+
268
285
<1> Compression controls memory usage and approximation error
269
286
270
287
The TDigest algorithm uses a number of "nodes" to approximate percentiles -- the
@@ -298,7 +315,9 @@ The HDR Histogram can be used by specifying the `method` parameter in the reques
298
315
299
316
[source,js]
300
317
--------------------------------------------------
318
+ GET latency/data/_search
301
319
{
320
+ "size": 0,
302
321
"aggs" : {
303
322
"load_time_outlier" : {
304
323
"percentiles" : {
@@ -312,6 +331,9 @@ The HDR Histogram can be used by specifying the `method` parameter in the reques
312
331
}
313
332
}
314
333
--------------------------------------------------
334
+ // CONSOLE
335
+ // TEST[setup:latency]
336
+
315
337
<1> `hdr` object indicates that HDR Histogram should be used to calculate the percentiles and specific settings for this algorithm can be specified inside the object
316
338
<2> `number_of_significant_value_digits` specifies the resolution of values for the histogram in number of significant digits
317
339
@@ -326,7 +348,9 @@ had a value.
326
348
327
349
[source,js]
328
350
--------------------------------------------------
351
+ GET latency/data/_search
329
352
{
353
+ "size": 0,
330
354
"aggs" : {
331
355
"grade_percentiles" : {
332
356
"percentiles" : {
@@ -337,5 +361,7 @@ had a value.
337
361
}
338
362
}
339
363
--------------------------------------------------
364
+ // CONSOLE
365
+ // TEST[setup:latency]
340
366
341
367
<1> Documents without a value in the `grade` field will fall into the same bucket as documents that have the value `10`.
0 commit comments