# Please help me with a secondary aggregation Problem

**URL:** <https://discuss.elastic.co/t/please-help-me-with-a-secondary-aggregation-problem/99533>\
**Category:** Elasticsearch\
**Created:** [September 6, 2017, 8:23am UTC](https://discuss.elastic.co/t/please-help-me-with-a-secondary-aggregation-problem/99533 "2017-09-06T08:23:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_smith](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@alex\_smith](https://discuss.elastic.co/u/alex_smith)\
**Post date:** [September 6, 2017, 8:23am UTC](https://discuss.elastic.co/t/please-help-me-with-a-secondary-aggregation-problem/99533/1 "2017-09-06T08:23:10Z")

</div>

Hi, i am recently using elasticsearch as a db now. and i met a secondary agregation problem that i cant found answer in the documents, so that's why i came here for help

the problem is , suppose we have `profile` and `activities` mapping in our `user` index , which defined as follow

```auto
PUT /user
{
  "settings": {
    "number_of_replicas" : 0
  },
  "mappings": {
    "profile": {
      "_all": { "enabled": false },
      "properties": {
        "user_id": { "type": "keyword" },
        "age": { "type": "integer" }
        }
    },
    "activities": {
      "_parent": { "type": "profile" },
      "_all": { "enabled": false },
       "properties": {
          "timestamp": { "type": "date", "format": "epoch_second" },
          "action": { "type": "integer"}
      }
    }
  }
}

```

now i want to check the user activities stats like how many people has 0-10 actions in a week and how many people has 11-20 actions in a week, etc

the first step is quite simple, i just use

```auto
GET /user/activities/_search?size=0
{
    "aggs": {
       "group-by-people": {
            "terms": {"field": "parent_id.keyword"}
        },
       "aggs": {
           "action-count": {
              "value_count": {"field": "parent_id.keyword"}
           }
       }
    }
}

```

so i could get every peple's id and actions count, the problem is how can i perform aggregation on the results, i need to then to make bucket based on the `action-count` field, and calculate the number of the matched people.

this looks like a common issue, i called (temporary ) it secondary aggregation, but i cant find any issue in the documents about it, please help

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [September 6, 2017, 4:42pm UTC](https://discuss.elastic.co/t/please-help-me-with-a-secondary-aggregation-problem/99533/2 "2017-09-06T16:42:33Z")

</div>

We support going from profile to activities, but not the other way around: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html)

---

<div class="post-metadata">

**Author:** ![alex\_smith](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@alex\_smith](https://discuss.elastic.co/u/alex_smith)\
**Post date:** [September 7, 2017, 2:11am UTC](https://discuss.elastic.co/t/please-help-me-with-a-secondary-aggregation-problem/99533/3 "2017-09-07T02:11:00Z")

</div>

so that means currently i cant solve this problem ?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [September 7, 2017, 7:18am UTC](https://discuss.elastic.co/t/please-help-me-with-a-secondary-aggregation-problem/99533/4 "2017-09-07T07:18:32Z")

</div>

Correct.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 5, 2017, 7:18am UTC](https://discuss.elastic.co/t/please-help-me-with-a-secondary-aggregation-problem/99533/5 "2017-10-05T07:18:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
