elasticsearch计算唯一值的平均值 [英] elasticsearch calculate average of unique values
本文介绍了elasticsearch计算唯一值的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Elasticsearch中动态计算唯一值的平均值?
How can I dynamically calculate the average of unique values in elasticsearch?
{ "price" : 10000, "color" : "red" }
{ "price" : 20000, "color" : "red" }
{ "price" : 30000, "color" : "green" }
{ "price" : 15000, "color" : "blue" }
{ "price" : 12000, "color" : "green" }
{ "price" : 20000, "color" : "red" }
{ "price" : 80000, "color" : "red" }
{ "price" : 25000, "color" : "blue" }
在以上数据中,如何获得颜色"字段的唯一值,然后获得每个颜色"字段的平均值?
In the above data, how can I get the unique values of the "color" field and then the averages for each of the unique "color" fields?
推荐答案
使用 avg
子聚合可以达到目的:>
{
"aggs": {
"colors": {
"terms": {
"field": "color"
},
"aggs": {
"average": {
"avg": {
"field": "price"
}
}
}
}
}
}
这篇关于elasticsearch计算唯一值的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文