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
}
]
}
}
}
ES date_histogram 聚合的更多相关文章
- ES Terms 聚合数据不确定性
Elasticsearch是一个分布式的搜索引擎,每个索引都可以有多个分片,用来将一份大索引的数据切分成多个小的物理索引,解决单个索引数据量过大导致的性能问题,另外每个shard还可以配置多个副本,来 ...
- ES 在聚合结果中进行过滤
ES查询中,先聚合,在聚合结果中进行过滤 { "size": 0, "aggs": { "terms": { "terms&quo ...
- (转载)es进行聚合操作时提示Fielddata is disabled on text fields by default
原文地址:http://blog.csdn.net/u011403655/article/details/71107415 根据es官网的文档执行 GET /megacorp/employee/_se ...
- (转)es进行聚合操作时提示Fielddata is disabled on text fields by default
根据es官网的文档执行 GET /megacorp/employee/_search { "aggs": { "all_interests": { " ...
- javaAPI操作ES分组聚合
连接es的客户端使用的 TransportClient SearchRequestBuilder requestBuilder = transportClient.prepareSearch(indi ...
- es date_histogram强制补零
es补零 GET /cars/transactions/_search { "size" : 0, "aggs": { "sales": { ...
- ES系列九、ES优化聚合查询之深度优先和广度优先
1.优化聚合查询示例 假设我们现在有一些关于电影的数据集,每条数据里面会有一个数组类型的字段存储表演该电影的所有演员的名字. { "actors" : [ "Fred J ...
- 时间序列数据库——索引用ES、聚合分析时加载数据用什么?docvalues的列存储貌似更优优势一些
加载 如何利用索引和主存储,是一种两难的选择. 选择不使用索引,只使用主存储:除非查询的字段就是主存储的排序字段,否则就需要顺序扫描整个主存储. 选择使用索引,然后用找到的row id去主存储加载数据 ...
- ES的聚合操作
构建数据: @Test public void createIndex(){ /** * 创建索引 * */ client. ...
随机推荐
- (十九)oracle 基础使用以及sql语句基础
oracle的安装与卸载 要记住数据库口令,适用于sys.system.sysman/dbsnmp等账户,而scott帐号密码默认为tiger, 以oracle 10g来说,scott账户默认是lo ...
- TrippleDESCSPEncrypt 加密解密试试看
public class TrippleDESCSPEncrypt { //12个字符 private static string customIV = "4vHKRj3yfzU=" ...
- 动态绑定easyui datagrid列名
根据实时数据在同一个DataGrid中显示不同字段,本身easyui并没有支持动态绑定列名,只有show属性显示或隐藏某字段.今天在网上看到直接修改easyui类库动态绑定列名的方法,废话不多说直接借 ...
- npm镜像指定用淘宝镜像去下载
使用npm下载,蜗牛,使用cnpm又觉得那啥,所以.把cnpm也就是淘宝镜像绑定成npm下载的代理,这样使用npm的时候其实是用淘宝镜像去下载,这感觉,good! 1. npm config set ...
- Flutter 流式布局列表实例+上拉加载
页面变化的几种方式: 一.StatefulWidget的setState形式 先声明两个变量. ; List<Map> list = []; 写了一个方法,获取数据: void _getH ...
- Hystrix多个线程池切换执行超时带来的问题(图解)
线程池切换带来的超时问题 上图有什么问题: Controller的Hystrx线程池已经到了超时时间,而FeignClient的Hystrx线程池还没到超时时间. 场景: Controller ...
- python线程互斥锁Lock(29)
在前一篇文章 python线程创建和传参 中我们介绍了关于python线程的一些简单函数使用和线程的参数传递,使用多线程可以同时执行多个任务,提高开发效率,但是在实际开发中往往我们会碰到线程同步问题, ...
- Oracle游标的简易用法
create or replace procedure NW_DelYW(iOPERATION_ID number, sUserID varchar2) is sCurDJBH yw_operatio ...
- Redis服务监控之RedisLive安装部署(亲测可用)
一.Redis服务安装部署 1.redis安装(linux系统) 下载 https://redis.io/ 安装依赖 yum install gcc tcl 解压.编译.安装(make & m ...
- unicode 格式 转汉字
function decodeUnicode($str){ return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', create_function( ...