title: Restrict aggregation to results of filter
body: <p>Given a set of documents that have a given value in one field, I want to know how many documents there are that have each value for a second field.</p>
  
  <p>I've tried to do that with a terms aggregation with the following query:</p>
  
  <pre><code>{
      "size": 0,
      "filter": {
          "term": {
              "field1": "value"
          }
      },
      "aggregations": {
          "field2" : {
              "terms" : { "field" : "field2" }
          }
      }
  }
  </code></pre>
  
  <p>but the returned counts show the number of documents with each value for the second field in the <em>whole index</em>, and not restricted to those documents with a given value for the first field.</p>
  
  <p>What am I doing wrong?</p>