我在elasticsearch中列出了包含各种文件的文档。文档如下所示。
{
"role": "api_user",
"apikey": "key1"
"data":{},
"@timestamp": "2021-10-06T16:47:13.555Z"
},
{
"role": "api_user",
"apikey": "key1"
"data":{},
"@timestamp": "2021-10-06T18:00:00.555Z"
},
{
"role": "api_user",
"apikey": "key1"
"data":{},
"@timestamp": "2021-10-07T13:47:13.555Z"
}
]
我想找出以1天为间隔的特定日期范围内存在的文档数量,假设是2021-10-05T00:47:13.555Z to 2021-10-08T00:13:13.555Z
我正在尝试下面的聚合结果。
{
"size": 0,
"query": {
"filter": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "2021-10-05T00:47:13.555Z",
"lte": "2021-10-08T00:13:13.555Z",
"format": "strict_date_optional_time"
}
}
}
]
}
}
},
"aggs": {
"data": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "day"
}
}
}
}
期望的输出应该是:-对于2021-10-06
,我应该得到2个文档,对于2021-10-07
,我应该得到1个文档,如果文档不存在,我应该得到计数为0。
发布于 2021-10-11 07:01:21
下面的解决方案有效
{
"size":0,
"query":{
"bool":{
"must":[
],
"filter":[
{
"match_all":{
}
},
{
"range":{
"@timestamp":{
"gte":"2021-10-05T00:47:13.555Z",
"lte":"2021-10-08T00:13:13.555Z",
"format":"strict_date_optional_time"
}
}
}
],
"should":[
],
"must_not":[
]
}
},
"aggs":{
"data":{
"date_histogram":{
"field":"@timestamp",
"fixed_interval":"12h",
"time_zone":"Asia/Calcutta",
"min_doc_count":1
}
}
}
}
https://stackoverflow.com/questions/69520831
复制相似问题