title: Aggregation + sorting +pagination in elastic search
body: <p>I need to do an aggregation + sorting + pagination in one of the indexes.</p>
  
  <p>I learned about internal functionality of Elastic search,</p>
  
  <p>I have 5 total shards, it will sort the individual shards and fetch the result, by default each shard will return  in 10 records. Then the 50 records are sorted again and it will fetch the top 10 record since by default size is 10.</p>
  
  <p>ouput:</p>
  
  <p>The aggregated results are returned in separate field named as "aggregations".In order to do pagination in this aggregated data,size and from are not working.</p>
  
  <p>So tired of doing termBuilder.size(500), now the logic was differs as per this link (<a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html" rel="noreferrer">http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html</a>)</p>
  
  <p>It leads to inaccuracy of data.</p>
  
  <p>Can any one suggest me how to deal with aggregation + pagination.</p>