【发布时间】:2021-03-26 12:47:02
【问题描述】:
我有一个 SendGrid 事件数据的索引:
"_source": {
"externalId": "9283cc1d-b003-xxxx-a5af-84fcf31c4181",
"email": "test@test.com",
"timestamp": 1616515214,
"event": "processed",
"uid": null,
"id": null,
"sendgridEventId": null,
"smtpId": null,
"sgMessageId": null,
"sgEventId": null,
"sendgridEvent": null,
"type": null,
"category": [],
"reason": null,
"status": null,
"url": null,
"useragent": null,
"ip": null,
"response": null,
"tls": null,
"attempt": null,
"sendAt": null,
"asmGroupId": null
}
现在,我喜欢使用 timestamp 属性汇总给定日期的所有这些事件。
GET /sendgridevententity/_search
{
"query":
{
"match_all": {}
},
"aggs": {
"amount_per_day": {
"date_histogram": {
"field": "timestamp",
"calendar_interval": "1d"
}
}
}
}
不幸的是,这只会产生所有单个事件,因为它们都有不同的时间戳,并且聚合不会按天对它们进行分组。
如何将时间戳转换为date,然后运行聚合?
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation elasticsearch-date