Joe Walsh
Joe Walsh

Reputation: 210

Solr get count of aggregation function

If a have Solr data for users and goals

{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}

I'm wanting to find out how many users have scored 1,2,3... goals in total.

So for the data above I want a query that can return

{goals: 3, count: 1}
{goals: 4, count: 2}

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

My query so far

{
  "user_facet":
  {
    "type":"terms",
    "field":"user_id",
    "facet":
    {
      "sum_of_goals":"sum(goals)"
    }
  }
}

Upvotes: 0

Views: 1469

Answers (1)

Persimmonium
Persimmonium

Reputation: 15791

I don't think you can get this with json facets. But for sure it's possible with Streaming Expressions. They are a bit more complex to get started, but you can accomplish many more things.

Upvotes: 1

Related Questions