我刚打酱油去了,不好意思

elasticsearch date_histogram 聚合结果首尾桶的时间发生偏移

Elasticsearch | 作者 hellowWorld | 发布于2017年12月06日 | 阅读数:3690

{
"size" : 0,
"query" : {
"bool" : {
"filter" : [
{
"range" : {
"time" : {
"from" : 1509956880000,
"to" : 1512548880000,
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"terms" : {
"url" : [
"127.0.0.1:8020/HelloHBuilder/0928/a.json",
"192.168.10.107:8049/mission/#!//mission/dashboard/dashboardView?btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999",
"192.168.10.107:8049/mission/#!//mission/viewTemplateQuery/view?viewOid=1190&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999",
"192.168.10.107:8049/mission/viewTemplateQuery/view?viewOid=1190&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999&btype=9999",
"localhost:8080/bsm-server/server/overview/generalView/queryDatasbyQuota?start=2017-10-20+20%3A17%3A34&end=2017-11-20+20%3A17%3A34&_=1511180055042"
],
"boost" : 1.0
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"aggregations" : {
"CNT" : {
"date_histogram" : {
"field" : "time",
"format" : "epoch_millis",
"time_zone" : "Asia/Shanghai",
"interval" : 64800000,
"offset" : 0,
"order" : {
"_key" : "asc"
},
"keyed" : false,
"min_doc_count" : 0,
"extended_bounds" : {
"min" : 1509956880000,
"max" : 1512548880000
}
},
"aggregations" : {
"category" : {
"terms" : {
"field" : "url",
"size" : 20,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : {
"static.avg" : "desc"
}
},
"aggregations" : {
"static" : {
"extended_stats" : {
"field" : "totalTime",
"sigma" : 2.0
}
}
}
}
}
}
}
}

第一个桶时间 {
"key_as_string": "1509940800000",
"key": 1509940800000,
"doc_count": 0,
"category": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
},

最后一个桶时间 {
"key_as_string": "1512532800000",
"key": 1512532800000,
"doc_count": 0,
"category": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
第一个桶的时间根本不在查询范围内,所有桶均出现了相同的偏移量,为何
已邀请:

mafa1993

赞同来自:

"interval" : 64800000, 的问题, es的时间切分不是你想的那样, 从开始时间, 每次增加interval , 或许和给定的时间段是否可以整除interval有关, 而且如果设置的interval中没有数据, 那么这个区间是不进行返回的

hellowWorld - 爱生活爱java

赞同来自:

es的时间切割我不太清楚,但是设置的interval中没有数据这个区间也是要返回的,只不过返回的桶的size为0吧。你将查询语句放到kibana里就可以看到了

要回复问题请先登录注册