title: Nested SQL select using elasticsearch
body: <p>How can I write this in elasticsearch:</p>
  
  <pre><code>    SELECT avg(sum) 
      FROM (
           SELECT sum(rev) as sum
           FROM table
           GROUP BY user_id
      )
  </code></pre>