我想聚集数据的月份和日期,我尝试与日期直方图聚合,但它考虑到完整的日期对象。
我有如下数据:
{
"created" : "2020-09-26",
"id" : 6,
"name" : "Halum khamu"
},
{
"created" : "2021-09-26",
"id" : 7,
"name" : "new new"
},
{
"created" : "2020-10-07",
"id" : 8,
"name" : "Halum new"
}
我使用这个查询:
GET /regulations/_search/
{
"aggs": {
"news_over_time": {
"date_histogram": {
"field": "created",
"calendar_interval": "day",
"keyed": true,
"format": "yyy-MM-dd",
"min_doc_count": 1
}
}
}
}
它为我返回数据:
"buckets" : {
"2020-09-26" : {
"key_as_string" : "2020-09-26",
"key" : 1600300800000,
"doc_count" : 1
},
"2021-09-26" : {
"key_as_string" : "2021-09-26",
"key" : 1601337600000,
"doc_count" : 1
},
"2020-10-07" : {
"key_as_string" : "2020-10-07",
"key" : 1632873600000,
"doc_count" : 1
}
}
但我的预期产出将不考虑今年:
"buckets" : {
"09-26" : {
"key_as_string" : "09-26",
"key" : 1600300800000,
"doc_count" : 2
},
"10-07" : {
"key_as_string" : "10-07",
"key" : 1632873600000,
"doc_count" : 1
}
}
我该怎么做?
1条答案
按热度按时间aemubtdh1#
没有直接的方法来解决这个问题,但这应该可以完成工作:
顺从的
编辑——实际上有一个更简单的方法: