1
回答
elasticsearch聚合后再加和
华为云实践训练营,热门技术免费实践!>>>   

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

select sum(fieldA) from table group by fieldB

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

求大神指导

举报
望尘
发帖于1年前 1回/272阅
{
	"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"
					}
				}
			}
		}
	}
}



--- 共有 1 条评论 ---
望尘虽然我已解决,但还是感谢你的回答,我也是用两层aggregation嵌套的,只不过我用的 Java API,^_^ 12个月前 回复
顶部