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:

db.events1.aggregate([
{$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?

Tnanks.

--
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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/00e64f0e-f26f-4126-b5c0-10e583d8499b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.