[英]Elastic search date_histogram extended_bounds
I want to get date_histogram during specific period, how to restrict the date period? 我想在特定时期获得date_histogram,如何限制日期? Should I use the extended_bounds parameter?
我应该使用extended_bounds参数吗? For example : I want to query the date_histogram between '2016-08-01' and '2016-08-31', and the interval is day.
例如:我想查询'2016-08-01'和'2016-08-31'之间的date_histogram,间隔是day。 I query with this expression :
我用这个表达式查询:
{
"aggs": {
"cf_loan": {
"date_histogram": {
"field": "createDate",
"interval": "day",
"format": "yyyy-MM-dd",
"min_doc_count": 0,
"extended_bounds": {
"min": "2016-08-01",
"max": "2016-08-31"
}
}
}
}
}
But I get the date_histogram not in the range. 但我得到的date_histogram不在范围内。
You're almost there, you need to add a range
query in order to only select documents whose createDate
field is in the desired range. 你几乎就在那里,你需要添加一个
range
查询,以便只选择其createDate
字段在所需范围内的文档。
{
"query": {
"range": { <---- add this range query
"createDate": {
"gte": "2016-08-01T00:00:00.000Z",
"lt": "2016-09-01T00:00:00.000Z"
}
}
},
"aggs": {
"cf_loan": {
"date_histogram": {
"field": "createDate",
"interval": "day",
"format": "yyyy-MM-dd",
"min_doc_count": 0,
"extended_bounds": {
"min": "2016-08-01",
"max": "2016-08-31"
}
}
}
}
}
The role of the extended_bounds
parameter is to make sure you'll get daily buckets from min
to max
even if there are no documents in them. 该角色
extended_bounds
参数是确保你会得到每天桶从min
到max
,即使有在他们没有文件。 For instance, say you have 1 document each day between 2016-08-04 and 2016-08-28, then without the extended_bounds
parameter, you'd get 25 buckets (2016-08-04, 2016-08-05, 2016-08-06, ..., 2016-08-28). 例如,假设您在2016-08-04和2016-08-28之间每天有1个文档,那么如果没有
extended_bounds
参数,您将获得25个桶(2016-08-04,2016-08-05,2016- 08-06,...,2016-08-28)。
With the extended_bounds
parameter, you'll also get the following buckets but with 0 documents: 使用
extended_bounds
参数,您还将获得以下存储桶,但有0个文档:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.