How to sub-aggregate an array that contains another field?

You can model the tags field as a nested type. Then you can used a nested aggregation to get to what you want.