I have tried to use a group_by with a date_histogram by month. Our example works like expected with "calendar_interval": "day" but returns nothing with "calendar_interval": "month". In fact it seems wo work with day, week and hour but not for month.
Sample Data
[
{
"productID": 1001,
"accountID": "1",
"timeStamp": "2023-02-28T07:00:15.043331859Z"
},
{
"productID": 1002,
"accountID": "1",
"timeStamp": "2023-02-28T07:00:15.043331859Z"
},
{
"productID": 1001,
"accountID": "2",
"timeStamp": "2023-02-28T07:00:15.043331859Z"
}
]
Transform
Group by month and accountID.
{
"source": {
"index": "product-tracking-events*"
},
"pivot": {
"group_by": {
"time": {
"date_histogram": {
"field": "timeStamp",
"calendar_interval": "month"
}
},
"account": {
"terms": {
"field": "accountID.keyword"
}
}
},
"aggregations": {
"productIDs": {
"cardinality": {
"field": "productID",
"precision_threshold": 1000
}
}
}
},
"frequency": "1m",
"sync": {
"time": {
"delay": "60s",
"field": "timeStamp"
}
},
"description": "Saves number of unique productIDs for an accountID",
"dest": {
"index": "transform-product-events"
}
}
Expected Result
We want to see the number of unique products per account. So account 1 had 2 products and account 2 had 1 product:
[
{
"date": "2023-02-01T00:00:00.0Z",
"account": "1",
"productIDs": 2
},
{
"date": "2023-02-01T00:00:00.0Z",
"account": "2",
"productIDs": 1
}
]