title: How to get the best children for each parent document in Elasticsearch?
body: <p>I use a parent/child relationship to store some documents:</p>
  
  <pre><code>{
      "A" : {
          "properties" : {
          }
      }
  }
  
  {
      "B" : {
          "_parent" : {
              "type" : "A"
          },
          "properties" : {
          }
      }
  }
  </code></pre>
  
  <p>In my use case I need to find the best <code>B</code> document for each <code>A</code> document. (Like a <code>has_parent</code> query and some filter which ensures that only the highest scored document for each parent is returned.)<br>
  Is there a nice solution for this problem?</p>