如何在ElasticSearch中获取百分位数 [英] How do I get percentiles with count in ElasticSearch
问题描述
我们正尝试在 ElasticSearch 中使用百分点聚合
我们正在使用ElasticSearch监控我们的API性能。我们存储的一组样本文件是
{name:GET / login,avg count:5}
pre>
{name:GET / login,avg:1.5,count:3}
{name:GET / login,avg :6.9,count:1}
{name:GET / login,avg:3.1,count:1}
其中
-
count
是一个GET / login
的数量到我们服务器的特定时间段。 -
avg
是平均响应时间。
我们使用以下查询获取百分位数。
GET / hist / t / _search
{
aggs:{
avg_time_percentile:{
百分位数:{
field:avg,
percents:[75,95,99]
}
}
}
}
我们得到以下回应
avg_time_percentile:{
values:{
75.0:3.75,
95.0 :5.549999999999999,
99.0:5.909999999999999
}
然而,想要的是:
avg_time_percentile:{
values:{
75.0:2 ,
95.0:4.349999999999998,
99.0:5.670000000000002
}
错误值的原因是,它正在采取例如 2.2
仅在一个记录中。但是计数是 5
,它应该被考虑5次。
我如何在ElasticSearch中执行。 / p>
而不是使用字段
,您可以使用脚本
,以便将多个字段合并在一起并运行这些新值的百分位数
POST / hist / t $ _
$ b {
aggs:{
avg_time_percentile:{
percentiles:{
script:{
inline:doc.avg.value * doc.count.value
},
percents:[75,95,99]
}
}
}
}
We are trying to generate Percentiles in ElasticSearch using Percentiles aggregation
We are monitoring our API performance with ElasticSearch. A sample set of documents that we store are
{"name": "GET /login", "avg":2.2, "count": 5}
{"name": "GET /login", "avg":1.5, "count": 3}
{"name": "GET /login", "avg":6.9, "count": 1}
{"name": "GET /login", "avg":3.1, "count": 1}
Where
count
is number ofGET /login
web requests coming to our server for a specific time period.avg
is average response time.
We uses following query to get percentile.
GET /hist/t/_search
{
"aggs": {
"avg_time_percentile": {
"percentiles": {
"field": "avg",
"percents" : [75, 95, 99]
}
}
}
}
We get following response
"avg_time_percentile": {
"values": {
"75.0": 3.75,
"95.0": 5.549999999999999,
"99.0": 5.909999999999999
}
However, what we want is:
"avg_time_percentile": {
"values": {
"75.0": 2,
"95.0": 4.349999999999998,
"99.0": 5.670000000000002
}
The reason for the incorrect value is, it is taking for e.g. 2.2
as only in one record. But the count is 5
and it should be considered 5 times.
How do I do it in ElasticSearch.
Instead of using field
you can use script
in order to combine several fields together and run the percentiles on those new values
POST /hist/t/_search
{
"aggs": {
"avg_time_percentile": {
"percentiles": {
"script": {
"inline": "doc.avg.value * doc.count.value"
},
"percents" : [75, 95, 99]
}
}
}
}
这篇关于如何在ElasticSearch中获取百分位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!