Please help me with a secondary aggregation Problem


(Alex Smith) #1

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

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

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


(Adrien Grand) #2

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


(Alex Smith) #3

so that means currently i cant solve this problem ?


(Adrien Grand) #4

Correct.


(system) #5

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