Filter query based on aggregation results

We have an index with the following document structure:
email: "",
stuff ..
email: ",

We need to get all records where the count of distinct email is > 2 for example. I know I can use an aggregation with a mininum doc count to find all counts of all records where there are at least 2 records for an email.

But what we need to do is actually get all the records where the count of distinct email is > X. So we need our query to constrain our results to only those records that match an aggregation.

I know that we can have a nested TopHits aggregation, but that is not good enough for us, because we need to be able to page through these results... there could be records where an email has 10k records for example. We need to be able to get these results in the Hits collection so that we can page them.

How would we go about doing something like that?

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