title: In ElasticSearch, how do I filter the nested documents in my result?
body: <p>Suppose, in ElasticSearch 5, I have data with nesting like:</p>
  
  <pre><code>{"number":1234, "names": [ 
    {"firstName": "John", "lastName": "Smith"}, 
    {"firstName": "Al", "lastName": "Jones"}
  ]},  
  ...
  </code></pre>
  
  <p>And I want to query for hits with number 1234 but <strong>return only</strong> the names that match "lastName": "Jones", so that my result omits names that don't match. In other words, <strong>I want to get back only part</strong> of the matching document, based on a term query or similar.</p>
  
  <p>A simple nested query won't do, as such would be filtering top-level results. Any ideas?</p>
  
  <pre><code>{ "query" : { "bool": { "filter":[
      { "term": { "number":1234} },
      ????  something with "lastName": "Jones" ????
  ] } } }
  </code></pre>
  
  <p>I want back: </p>
  
  <pre><code>hits: [
     {"number":1234, "names": [ 
       {"firstName": "Al", "lastName": "Jones"}
     ]},  
     ...
  ]
  </code></pre>