欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

7聚合--1度量聚合

程序员文章站 2024-03-25 11:15:58
...
[b]计算平均分数[/b]
{
"aggs" : {
"avg_grade" : { "avg" : { "field" : "grade" } }
}
}
avg代表平均的意思,列为grade。上面可能返回
{
...

"aggregations": {
"avg_grade": {
"value": 75
}
}
}
聚合的名字avg_grade会被当做返回的key.

[b]基数聚集[/b]
计算同一个作者的
{
"aggs" : {
"author_count" : {
"cardinality" : {
"field" : "author"
}
}
}
}
返回
{
...

"aggregations": {
"author_count": {
"value": 19
}
}
}

[b]扩展的数据聚集[/b]

{
"aggs" : {
"grades_stats" : { "extended_stats" : { "field" : "grade" } }
}
}
返回
{
...

"aggregations": {
"grade_stats": {
"count": 9,
"min": 72,
"max": 99,
"avg": 86,
"sum": 774,
"sum_of_squares": 67028,
"variance": 51.55555555555556,
"std_deviation": 7.180219742846005,
"std_deviation_bounds": {
"upper": 100.36043948569201,
"lower": 71.63956051430799
}
}
}
}


[b]最大值[/b]
{
"aggs" : {
"max_price" : { "max" : { "field" : "price" } }
}
}
返回
 {
...

"aggregations": {
"max_price": {
"value": 35
}
}
}

[b]最小值[/b]
{
"aggs" : {
"min_price" : { "min" : { "field" : "price" } }
}
}
返回
{
...

"aggregations": {
"min_price": {
"value": 10
}
}
}

[b]统计信息[/b]
{
"aggs" : {
"grades_stats" : { "stats" : { "field" : "grade" } }
}
}
返回
{
...

"aggregations": {
"grades_stats": {
"count": 6,
"min": 60,
"max": 98,
"avg": 78.5,
"sum": 471
}
}
}

[b]统计和[/b]
{
"query" : {
"constant_score" : {
"filter" : {
"range" : { "timestamp" : { "from" : "now/1d+9.5h", "to" : "now/1d+16h" }}
}
}
},
"aggs" : {
"intraday_return" : { "sum" : { "field" : "change" } }
}
}
返回
{
...

"aggregations": {
"intraday_return": {
"value": 2.18
}
}
}

[b]计数[/b]
{
"aggs" : {
"grades_count" : { "value_count" : { "field" : "grade" } }
}
}
返回
 {
...

"aggregations": {
"grades_count": {
"value": 10
}
}
}
相关标签: es