title: Elasticsearch aggregation order by top hit score
body: <p>I want to order buckets by doc.score of top_hit. My current implementation is below. </p>
  
  <pre><code>  group_by_iid: {
      terms: {
        field: 'iid',
        order: { max_score: 'desc' },
        size: 0
      },
      aggs: {
        max_score: { max: { script: 'doc.score' } },
        top_hit: {
          top_hits: {
            sort: [{ source_priority: { order: 'desc' } }],
            size: 1
          }
        }
      }
    }
  </code></pre>
  
  <p>This is wrong because buckets are ordered by their top score, not their top source_priority document's score. Is there a way to solve this problem?</p>