我可以用这段代码计算每天匹配查询字符串的点击数,但是如果一整周都没有点击数,那么查询将不返回任何结果--而不是每天返回0。有没有办法可以“默认”为0?
GET index/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{"match_phrase": {
"message": "Cannot login"
}
},
{"range": {
"@timestamp":{
"gte":"2021-07-01",
"lte":"2021-07-07"
}
}
}
]
}
},
"aggs": {
"hit_count_per_day": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "day"
}
}
}
}
2条答案
按热度按时间7rtdyuoh1#
对于此建议,您需要将
extended_bounds
添加到聚合中,如下所示:如果它不能解决您的问题,请告诉我。
um6iljoc2#
当聚合响应中的elasticsearch返回0时,表示由于筛选器的原因,有值未显示。
例如,我有一个关于“region”的术语过滤器:“mexico”,它返回给我:
前两个是因为它们在数据集(索引)中,但经过筛选。
希望能有所帮助。