Aggregations for dynamic key value pairs

I think I figured out the best approach by following recommendations in this post..

https://discuss.elastic.co/t/aggregate-over-multiple-keys-in-the-document-without-knowing-the-key-details/158238

Thank you!