Referencing query field values in global aggregation

I have documents that contain a (multi-value) "category_ids" field. During a search, I want to find out how many total (unfiltered) documents are in each of the results category_ids.

I've been playing around with a global aggregation which contains a terms aggregation on the category_ids field. However I haven't been able to figure out how to filter the category ids so that only category ids in the searches result set are returned. Is it possible to reference the search result field values in an aggregation? Is this kind of mixing of global/non-global aggregation at all possible, or do I need to do two separate queries?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.