如下面这个,下面是我测试的数据量,比如我统计一个时间范围内不重复的stbid个数
数据量小时可以看到 buckets 下有两类 key ,但是一旦数据量大了,我如何统计buckets下有多少key呢?
相当于 select count(stbid) from table where collecttime>'2016-09-26 15:00:00' and collecttime<'2016-09-26 17:00:00' ;
望高人指教
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 10,
"max_score": 0,
"hits": [ ]
},
"aggregations": {
"aggInfo": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "009903FF00473340000090D8F35D4FE2",
"doc_count": 5
}
,
{
"key": "2710029900701590000030F31D96B797",
"doc_count": 5
}
]
}
}
}
数据量小时可以看到 buckets 下有两类 key ,但是一旦数据量大了,我如何统计buckets下有多少key呢?
相当于 select count(stbid) from table where collecttime>'2016-09-26 15:00:00' and collecttime<'2016-09-26 17:00:00' ;
望高人指教
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 10,
"max_score": 0,
"hits": [ ]
},
"aggregations": {
"aggInfo": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "009903FF00473340000090D8F35D4FE2",
"doc_count": 5
}
,
{
"key": "2710029900701590000030F31D96B797",
"doc_count": 5
}
]
}
}
}
5 个回复
martindu - 搜披露创始人
赞同来自: lzyue 、leighton_buaa
leighton_buaa
赞同来自:
{
"aggs": {
"your_agg_name": {
"terms": {
"field": "field_name",
"size": 10
}
}
}
}
lzyue
赞同来自:
"query": {
"range": {
"currenttime": {
"from": "2016-09-26 14:25:00",
"to": "2016-09-26 14:30:00",
"include_lower": true,
"include_upper": false
}
}
},
"size": 0,
"aggregations": {
"aggInfo": {
"terms": {
"field": "stbid",
"size": 10
}
}
}
这样查询的结果是 下面那些,其实我想要的统计结果是 2 也就是 buckets 下有两个 key
现在我不知道怎么得到这个 2 数据量小时我可以一个一个看,十万,百万数量量时我没办法一个一个数,所以有没有一种count的方法把这个 2 统计出来呢
{
"took": 50,
"timed_out": false,
"_shards": {
"total": 1039,
"successful": 1039,
"failed": 0
},
"hits": {
"total": 80,
"max_score": 0,
"hits": [ ]
},
"aggregations": {
"aggInfo": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "009903FF00473340000090D8F35D4FE2",
"doc_count": 40
}
,
{
"key": "2710029900701590000030F31D96B797",
"doc_count": 40
}
]
}
}
}
leighton_buaa
赞同来自:
lzyue
赞同来自: