我需要在 Timestamp 上创建 15m 桶,然后在每个时间戳中,我需要对每种类型的书籍进行求和,当然还有书籍的总数。
例如,我的数据如下
[
{
"books":[
{
"id":0,
"count":10
},
{
"id":1,
"count":11
},
{
"id":2,
"count":7
},
{
"id":3,
"count":9
},
{
"id":4,
"count":16
}
],
"timestamp":1613693700000,
"total":53
},
{
"books":[
{
"id":0,
"count":0
},
{
"id":1,
"count":4
},
{
"id":2,
"count":9
},
{
"id":3,
"count":10
},
{
"id":4,
"count":1
}
],
"timestamp":1613694600000,
"total":24
}
]
我需要如下输出:
[
{
"timestamp":1613693700000,
"total_count":77,
"data":[
{
"id":0,
"count":10
},
{
"id":1,
"count":15
},
{
"id":2,
"count":16
},
{
"id":3,
"count":19
},
{
"id":4,
"count":17
}
]
}
]
我已经尝试过下面的查询,现在我被嵌套查询困住了,以获取每个时间戳桶中每种书籍类型的总和。在这方面需要帮助。
{
"aggs": {
"count": {
"date_histogram": {
"field": "timestamp",
"interval": "15m"
},
"aggs": {
"total_count": {
"sum": {
"field": "total"
}
}
}
}
}
}