es 时间字段聚合_ES date_histogram 聚合

如下

GET cars/index/_search

{

"size":0,

"aggs": {

"sales": {

"date_histogram": {//按照日期时间聚合分析数据

"field": "sold",//分析的字段

"interval": "month",//按照月份间隔

"format": "yyyy-MM-dd",//日期格式

"min_doc_count": 0,// 没有数据的月份返回0

"extended_bounds":{//强制返回的日期区间,是连续的

"min":"2014-01-01",

"max":"2018-12-31"

}

}

}

}

}

结果如下,拿到数据后方便进行图表分析,这样区间内连续的数据都可以看得很清晰

{

"took": 7,

"timed_out": false,

"_shards": {

"total": 5,

"successful": 5,

"failed": 0

},

"hits": {

"total": 8,

"max_score": 0,

"hits": []

},

"aggregations": {

"sales": {

"buckets": [

{

"key_as_string": "2014-01-01",

"key": 1388534400000,

"doc_count": 1

},

{

"key_as_string": "2014-02-01",

"key": 1391212800000,

"doc_count": 1

},

{

"key_as_string": "2014-03-01",

"key": 1393632000000,

"doc_count": 0

},

{

"key_as_string": "2014-04-01",

"key": 1396310400000,

"doc_count": 0

},

{

"key_as_string": "2014-05-01",

"key": 1398902400000,

"doc_count": 1

},

{

"key_as_string": "2014-06-01",

"key": 1401580800000,

"doc_count": 0

},

{

"key_as_string": "2014-07-01",

"key": 1404172800000,

"doc_count": 1

},

{

"key_as_string": "2014-08-01",

"key": 1406851200000,

"doc_count": 1

},

{

"key_as_string": "2014-09-01",

"key": 1409529600000,

"doc_count": 0

},

{

"key_as_string": "2014-10-01",

"key": 1412121600000,

"doc_count": 1

},

{

"key_as_string": "2014-11-01",

"key": 1414800000000,

"doc_count": 2

},

{

"key_as_string": "2014-12-01",

"key": 1417392000000,

"doc_count": 0

},

{

"key_as_string": "2015-01-01",

"key": 1420070400000,

"doc_count": 0

},

{

"key_as_string": "2015-02-01",

"key": 1422748800000,

"doc_count": 0

},

{

"key_as_string": "2015-03-01",

"key": 1425168000000,

"doc_count": 0

},

{

"key_as_string": "2015-04-01",

"key": 1427846400000,

"doc_count": 0

},

{

"key_as_string": "2015-05-01",

"key": 1430438400000,

"doc_count": 0

},

{

"key_as_string": "2015-06-01",

"key": 1433116800000,

"doc_count": 0

},

{

"key_as_string": "2015-07-01",

"key": 1435708800000,

"doc_count": 0

},

{

"key_as_string": "2015-08-01",

"key": 1438387200000,

"doc_count": 0

},

{

"key_as_string": "2015-09-01",

"key": 1441065600000,

"doc_count": 0

},

{

"key_as_string": "2015-10-01",

"key": 1443657600000,

"doc_count": 0

},

{

"key_as_string": "2015-11-01",

"key": 1446336000000,

"doc_count": 0

},

{

"key_as_string": "2015-12-01",

"key": 1448928000000,

"doc_count": 0

},

{

"key_as_string": "2016-01-01",

"key": 1451606400000,

"doc_count": 0

},

{

"key_as_string": "2016-02-01",

"key": 1454284800000,

"doc_count": 0

},

{

"key_as_string": "2016-03-01",

"key": 1456790400000,

"doc_count": 0

},

{

"key_as_string": "2016-04-01",

"key": 1459468800000,

"doc_count": 0

},

{

"key_as_string": "2016-05-01",

"key": 1462060800000,

"doc_count": 0

},

{

"key_as_string": "2016-06-01",

"key": 1464739200000,

"doc_count": 0

},

{

"key_as_string": "2016-07-01",

"key": 1467331200000,

"doc_count": 0

},

{

"key_as_string": "2016-08-01",

"key": 1470009600000,

"doc_count": 0

},

{

"key_as_string": "2016-09-01",

"key": 1472688000000,

"doc_count": 0

},

{

"key_as_string": "2016-10-01",

"key": 1475280000000,

"doc_count": 0

},

{

"key_as_string": "2016-11-01",

"key": 1477958400000,

"doc_count": 0

},

{

"key_as_string": "2016-12-01",

"key": 1480550400000,

"doc_count": 0

},

{

"key_as_string": "2017-01-01",

"key": 1483228800000,

"doc_count": 0

},

{

"key_as_string": "2017-02-01",

"key": 1485907200000,

"doc_count": 0

},

{

"key_as_string": "2017-03-01",

"key": 1488326400000,

"doc_count": 0

},

{

"key_as_string": "2017-04-01",

"key": 1491004800000,

"doc_count": 0

},

{

"key_as_string": "2017-05-01",

"key": 1493596800000,

"doc_count": 0

},

{

"key_as_string": "2017-06-01",

"key": 1496275200000,

"doc_count": 0

},

{

"key_as_string": "2017-07-01",

"key": 1498867200000,

"doc_count": 0

},

{

"key_as_string": "2017-08-01",

"key": 1501545600000,

"doc_count": 0

},

{

"key_as_string": "2017-09-01",

"key": 1504224000000,

"doc_count": 0

},

{

"key_as_string": "2017-10-01",

"key": 1506816000000,

"doc_count": 0

},

{

"key_as_string": "2017-11-01",

"key": 1509494400000,

"doc_count": 0

},

{

"key_as_string": "2017-12-01",

"key": 1512086400000,

"doc_count": 0

},

{

"key_as_string": "2018-01-01",

"key": 1514764800000,

"doc_count": 0

},

{

"key_as_string": "2018-02-01",

"key": 1517443200000,

"doc_count": 0

},

{

"key_as_string": "2018-03-01",

"key": 1519862400000,

"doc_count": 0

},

{

"key_as_string": "2018-04-01",

"key": 1522540800000,

"doc_count": 0

},

{

"key_as_string": "2018-05-01",

"key": 1525132800000,

"doc_count": 0

},

{

"key_as_string": "2018-06-01",

"key": 1527811200000,

"doc_count": 0

},

{

"key_as_string": "2018-07-01",

"key": 1530403200000,

"doc_count": 0

},

{

"key_as_string": "2018-08-01",

"key": 1533081600000,

"doc_count": 0

},

{

"key_as_string": "2018-09-01",

"key": 1535760000000,

"doc_count": 0

},

{

"key_as_string": "2018-10-01",

"key": 1538352000000,

"doc_count": 0

},

{

"key_as_string": "2018-11-01",

"key": 1541030400000,

"doc_count": 0

},

{

"key_as_string": "2018-12-01",

"key": 1543622400000,

"doc_count": 0

}

]

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值