elasticsearch聚合后再加和

望尘 发布于 2016/11/01 09:24
阅读 400
收藏 0

想实现一个统计功能,类似数据库的sql

select sum(fieldA) from table group by fieldB

看了官网和网上的资料,都是只能单独统计某一列的sum、avg之类的,或是文档的count数,但没找到这种先group by再计算另外一列的sum和的

求大神指导

加载中
0
bag
bag
{
	"from": 0,
	"size": 0,
	"query": {
		"bool": {
			"must": {
				"range": {
					"TIME": {
						"from": 20151216,
						"to": 20151217,
						"include_lower": true,
						"include_upper": true
					}
				}
			}
		}
	},
	"_source": {
		"includes": [
			"NAME",
			"COUNT"
		],
		"excludes": []
	},
	"fields": "NAME",
	"aggregations": {
		"INDNAME1": {
			"terms": {
				"field": "NAME",
				"size": 200
			},
			"aggregations": {
				"COUNT(*)": {
					"value_count": {
						"field": "_index"
					}
				}
			}
		}
	}
}



望尘
望尘
虽然我已解决,但还是感谢你的回答,我也是用两层aggregation嵌套的,只不过我用的 Java API,^_^
返回顶部
顶部