title: elasticsearch exclude aggregation bucket by subaggregation doc_count
body: <p>I think it'll be easier to explain with a query. Consider my query:</p>
  
  <pre><code>GET _search
  {
     "aggs": {
        "group_by_app": {
           "terms": {
              "field": "application"
           }
        },
        "aggs": {
           "installs": {
              "filter": {
                 "fquery": {
                    "query": {
                       "match": {
                          "action": "install"
                       }
                    },
                    "_cache": true
                 }
              }
           },
           "launches": {
               "filter": {
                 "fquery": {
                    "query": {
                       "match": {
                          "action": "launch"
                       }
                    },
                    "_cache": true
                 }
              }
           }
        }
     }
  }
  </code></pre>
  
  <p>This returns me with below result:</p>
  
  <pre><code>"aggregations": {
        "apps": {
           "buckets": [
              {
                 "key": "app1",
                 "doc_count": 2313,
                 "launches": {
                    "doc_count": 0
                 },
                 "installs": {
                    "doc_count": 48
                 }
              },
              {
                 "key": "app2",
                 "doc_count": 5,
                 "launches": {
                    "doc_count": 0
                 },
                 "installs": {
                    "doc_count": 0
                 }
              },
           ]
       }
  }
  </code></pre>
  
  <p>Now if you notice, installs and launches are both 0 for app2. I do not want the bucket for key = "app2" to show up in the result if both sub-aggregates launches and installs are 0. </p>
  
  <p>I saw <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_minimum_document_count" rel="nofollow">min_doc_count</a> and was wondering if it was possible to do something similar for my case?</p>
  
  <p>[EDIT]: The other thing I thought that I could try was that, instead of doing aggregation "group_by_app" for every possible "action", If I could aggregate it over ONLY "action" = "install" OR "action" = "launch". So basically what I mean is that the bucket aggregation is only over "action" = "launch" OR "install", and sub-aggregation are basically the same in the query. I can do a min_doc_count over the bucket aggregation to not show sub-aggregation results. However aggregation only allows term/terms or filter and not both. If somebody can suggest an alternative way to achieve that, even that would be a great help!</p>