Aggregate sub document use N1QL

Suppose I have some documents like this:

{
   "date": 20161205,
   "session": 3,
   "events": {
       "e1": {
           "count": 1
       },
       "e2": {
           "count": 2,
       }
  }
}
{
   "date": 20161206,
   "session": 2,
   "events": {
       "e1": {
           "count": 1
       }
  }
}

How to use N1QL to aggregate all docs and merge events object to get this result?

{
   "session": 5,
   "events": {
       "e1": {
           "count": 2
       },
       "e2": {
           "count": 2,
       }
  }
}

Thanks for any help!

Have you looked at GROUP BY, SUM(), and ARRAY_AGG()?

See http://stackoverflow.com/questions/40489388/couchbase-aggregation-of-nested-field