title: Elastic Search, limit results size by buckets count instead of documents
body: <p>I have millions of log documents for about thousand of classifieds, I want to search all of the log entries and put each one of them the the correct bucket where every bucket is a classified(with the unique id of the classified).I know how to limit the number of documents but is there a way to limit the number of buckets instead?</p>
  
  <pre><code>{  
     "size":10 #this limits by the docs length
      "aggregations": {
        "clfds": {
           "terms": {
              "field": "clsfd_id"
           }
        }
      },
     "sort":[  
        {  
           "clsfd_id":{  
              "order":"asc"
           }
        },
     ],
     "query":{  
        "filtered":{  
           "query":{  
              "match_all":{  
  
              }
           },
           "filter":{  
              "bool":{  
                 "should":[  
                      #filled dynamically
                 ],
              }
           }
        }
     }
  }
  </code></pre>