Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DocumentDB - Group By Aggregates

I have a colleciton in Elastic Search where we store events, and aggregate these in reports such as:

  • number of events/day over the last week
  • number of events/hour over the last 24h

enter image description here

We'd like to move to DocumentDB, but with no support for GROUPING, I don't see how I could implement this without making 7+24 queries. Any ideas?

Thanks

like image 308
wmmhihaa Avatar asked Mar 01 '17 13:03

wmmhihaa


2 Answers

For information, DocumentDB does now support Aggregates (as of March 8th 2017), for the following operations:

SUM and AVG for numeric values, COUNT, MIN, and MAX over numbers, strings, Booleans, and nulls.

Official Microsoft documentation has been updated, and can be found here.

Please note that Grouping support has not been added to Aggregate Functions; a User Voice issue has been opened to request this, and can be upvoted here.

like image 178
dmcquiggin Avatar answered Nov 03 '22 01:11

dmcquiggin


Based on my understanding, you want to move your event data to DocumentDb as a document in a collection. As your said, DocumentDb is not support for aggregate operations now, but the feature will be supported in the future as the offical site said. However, per my experience, you can use the stored procedure of DocumentDb to implement your needs, and automatically count the number of the event documents per the periods as you want to store as a new document of a new collection which for per day/hour via database trigger, please refer to the offical tutorial DocumentDB server-side programming: Stored procedures, database triggers, and UDFs to know it.

Meanwhile, I discovered a SO thread Grouping by a field in DocumentDB which is very helpful for you. The answerer has written a library documentdb-lumenize based on DocumentDb stored procedure that you can try it.

like image 39
Peter Pan Avatar answered Nov 03 '22 01:11

Peter Pan