But I can't use text_agg aggregation, because top hits doesn't support sub aggregations.
I'm expecting this response: "buckets": [ { "key": "bar", "doc_count": 2 }]
I guess retrieving ids and then aggregating them would be very heavy operation for the client.
Maybe scripting could help?
Update: I found a very non-flexible workaround. See here: http://stackoverflow.com/a/39788948/4769188
But I'm still looking for better solution.