title: Solr get count of aggregation function
body: <p>If a have Solr data for users and goals</p>
  
  <pre><code>{user_id: user1,goals: 1}
  {user_id: user1,goals: 3}
  {user_id: user2,goals: 0}
  {user_id: user2,goals: 4}
  {user_id: user3,goals: 2}
  {user_id: user3,goals: 1}
  </code></pre>
  
  <p>I'm wanting to find out how many users have scored 1,2,3... goals in total.</p>
  
  <p>So for the data above I want a query that can return</p>
  
  <pre><code>{goals: 3, count: 1}
  {goals: 4, count: 2}
  </code></pre>
  
  <p>So far I have a query that can return the total number of goals for each user but am not sure if it's possible to facet on the totals</p>
  
  <p>My query so far</p>
  
  <pre><code>{
    "user_facet":
    {
      "type":"terms",
      "field":"user_id",
      "facet":
      {
        "sum_of_goals":"sum(goals)"
      }
    }
  }
  </code></pre>