title: ES: Bucket agg + top_hits + scroll? How to return all hits (more than `size+from` max) in buckets?
body: <p>I'm running an elasticsearch filter with a large no. (~10million hits) of results. My <code>from+size</code> max is the default (10,000 hits). I'd like to aggregate based on a field, and return all the hits for the filter in all the buckets (not just the counts).  </p>
  
  <p>I know that I can use the <code>top_hits</code> to get the actual docs in each bucket (<a href="https://stackoverflow.com/questions/35950827/elasticsearch-retriving-documents-belonging-to-buckets?noredirect=1&amp;lq=1">ElasticSearch: retriving documents belonging to buckets</a>) but I think I need to scroll to get them all (to get more than the first 10000 hits). Can I scroll and aggregate? The <code>scroll</code> api fails when I run it with an aggregation. </p>
  
  <p>Currently, I have two solutions both seem not that great: </p>
  
  <ol>
  <li><p>run multiple filter queries, say 1 for each bucket (and then I don't need to use the aggregation + top_hits command). (too slow for my application) </p></li>
  <li><p>run 1 big filter query, and don't aggregate, but use the scroll api to get all the hits. Then I'll put them in the respective buckets here on my host. (ok, but seems like ES is set up for aggregating these into buckets for me and has more resources to do this work)  </p></li>
  </ol>
  
  <p>Are there better ways to deal with this? </p>
  
  <p>This seems related to this: ( <a href="https://stackoverflow.com/questions/33019482/paging-elasticsearch-aggregation-results">Paging elasticsearch aggregation results</a> ) although scroll api isn't mentioned (unless that is what they mean by paging?)</p>