Time-series with aggregation in Solr streaming expression

Viewed 28

I have documents like these in Solr:

{
    "category": "1",
    "views": 100,
    "created_at": "2022-08-23T07:43:25.567Z"
},
{
    "category": "2",
    "views": 300,
    "created_at": "2022-08-23T09:43:25.567Z"
},
{
    "category": "1",
    "views": 400,
    "created_at": "2022-08-22T08:43:25.567Z"
},
{
    "category": "1",
    "views": 600,
    "created_at": "2022-08-16T08:43:25.567Z"
}

I would like to run a streaming expression that returns how many views the documents have in total per category per week. So for the documents above, the result should be as follows:

{
    "1": { "2022-08-22T00:00:00": 500, "2022-08-15T00:00:00": 600 },
    "2": { "2022-08-22T00:00:00": 300 }
}

So in short, I would like to aggregate the documents both by a simple field (category) and by a timestamp (created_at), the latter with a weekly resolution (Monday of the week of created_at). How can I do this?

0 Answers
Related