Aggregation in ES like MongoDB

Hi all,

I have many documents like
{'user': 1, 'type': 1},
{'user': 2, 'type': 1},
{'user': 2, 'type': 2},
{'user': 3, 'type': 1},
{'user': 4, 'type': 1} ...

Then, I have this aggregation in MongoDB aggregation pipeline:

{$group: {_id: "$user", events:{$addToSet: '$type'}}},
{$group: {_id: "$events", counter: {$sum: 1}}},

So, after first phase (aggregate by user), i have:
user1-> 1
user2 -> 1,2
user3 -> 1
user4 -> 1

And after second (aggregate by 'events' set and count):
1 -> 3
1,2 -> 1
(this is the desired result)

Can I do something similar to this in ElasticSearch aggregation?


You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit