Sum aggregation with results from other aggregations?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Sum aggregation with results from other aggregations?

Josh Harrison
Is it possible to create an aggregation where I can do a sum on the results of a sub bucket?

I'm working on twitter data. In this data I have a bunch of retweets of different users.
Say that user A has 10 tweets that are retweeted a hundred times in my dataset. I want to find the maximum retweet_count for each individual tweet, and then I want to find the sum of all of those maximums from an individual user.
This is the base query structure I'm working with: 
{
  "aggs": {
    "user_id": {
      "terms": {
        "field": "retweet_user_id"
      },
      "aggs": {
        "tweet_ids": {
          "terms": {
            "field": "retweet_id",
            "order": "max_tweet.value"
          },
          "aggs": {
            "max_tweet": {
              "max": {
                "field": "retweet_count"
              }
            }
          }
        }
      }
    }
  }
}


Importantly here, I don't want to just take a sum of "retweet_count" for a given retweet_user_id - this doesn't give the max value per tweet.

Essentially, is it possible for me to take a sum of the agg results at user_id.tweet_ids.max_tweet.value, and use that as an "order" term in the user_id terms agg?


--
Please update your bookmarks! We have moved to https://discuss.elastic.co/
---
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/100b463d-0f95-4801-aec7-e32544624518%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.