[英]how to get the total value of field in kibana 4.x
I need to get the total value of field in Kibana using script field . 我需要使用脚本字段获取Kibana中字段的总值 。
eg) if id field have values like 1, 2, 3, 4, 5 例如)如果id字段的值类似于1、2、3、4、5
I am looking to sum
up all the values of id, I am expecting the output is 15. 我希望
sum
id的所有值,我希望输出是15。
I need to achieve the below formula after getting total of each field. 获取每个字段的总和后,我需要实现以下公式。
lifetime=a-b-c-(d-e-f)*g
here a,b,c,d,e,f,g all are total of the each field values. 这里的a,b,c,d,e,f,g全部是每个字段值的总和。
for more info please refer this question which is raised by me. 有关更多信息,请参阅我提出的这个问题 。
You could do something like this in your scripted fields
: 您可以在
scripted fields
:
doc['id'].value
Hence, you could use a sum
aggregation to get the total value in Kibana
. 因此,您可以使用
sum
来获取Kibana
的总价值。
This SO could be handy! 这个SO可以很方便!
EDIT 编辑
If you're trying to do it using Elasticsearch
, you could do something like this within your request body: 如果您尝试使用
Elasticsearch
,则可以在请求正文中执行以下操作:
"aggs":{
"total":{
"sum":{
"script":"doc['id'].value"
}
}
}
You could follow up this ref , but then if you're using painless
make sure you do include it within lang
. 你可以跟进这个裁判 ,但随后如果您在使用
painless
确保你包括它内lang
。 related SO 相关SO
You can definitely use sum aggregations to get the sum of id, but to further equate your formula, you can take a look at pipeline aggregations to use the sum value for further calculations. 您绝对可以使用求和聚合来获取id的总和,但是为了进一步使公式等式,您可以查看管道聚合以使用和值进行进一步的计算。
Take a look at bucket script aggregation , with proper bucket path to sum aggregator you can achieve your solution. 看一下存储桶脚本聚合 ,使用正确的存储桶路径对聚合器求和,就可以实现您的解决方案。
For sample documents 对于样本文件
{
"a":100,
"b":200,
"c":400,
"d":600
}
query 询问
{
"size": 0,
"aggs": {
"result": {
"terms": {"script":"'nice to have it here'"},
"aggs": {
"suma": {
"sum": {
"field": "a"
}
},
"sumb": {
"sum": {
"field": "b"
}
},
"sumc": {
"sum": {
"field": "c"
}
},
"equation": {
"bucket_script": {
"buckets_path": {
"suma": "suma",
"sumb": "sumb",
"sumc" : "sumc"
},
"script": "suma + sumb + 2*sumc"
}
}
}
}
}
}
Now you can surely add term filter on each sum agg to filter the summation for each sum aggregator. 现在,您可以确定在每个sum agg上添加术语过滤器,以过滤每个sum聚合器的总和。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.