title: Elasticsearch filtering aggregated results where count greater than x
body: <p>I've got the following elastic search query in order to get the highest total ms from Elastic Search grouped by market id.</p>
  
  <pre><code>    {
    "from": 0,
    "size": 0,
    "query": {
    "filtered": {
      "filter": {
        "and": [
          {
            "term": {
              "@type": "tradelog"
            }
          },
          {
            "range": {
              "@timestamp": {
                "gte": "now-7d",
                "lt": "now"
              }
            }
          },
          {
            "range": {
              "TotalMs": {
                "gte": 200,
                "lt": 2000
              }
            }
          }
        ]
      }
    }
  
  },
  "aggregations": {
        "the_name": {
           "terms": {
              "field": "Market",
              "order" : { "totalms_avg" : "desc" }
           },
           "aggregations": {
              "totalms_avg": {
                 "avg": {
                    "field": "TotalMs"
                 }
              }
           }
        }
     }
  }
  </code></pre>
  
  <p>This query returns several buckets that only have 1 result which are outliers in my data so I do not want them to be included.  Is it possible to filter out any buckets with a count of less than 5?  The elastic search equivalent to SQLs 'HAVING' clause.</p>