# Aggregation search

**URL:** <https://discuss.elastic.co/t/aggregation-search/53133>\
**Category:** Elasticsearch\
**Created:** [June 17, 2016, 9:09am UTC](https://discuss.elastic.co/t/aggregation-search/53133 "2016-06-17T09:09:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kZk93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kzk93/32/10379_2.png) [@kZk93](https://discuss.elastic.co/u/kZk93)\
**Post date:** [June 17, 2016, 9:09am UTC](https://discuss.elastic.co/t/aggregation-search/53133/1 "2016-06-17T09:09:09Z")

</div>

Actually I'm working with bunch of data represented by the following mapping:

```
"users" : {
        "properties" : {
          "__v" : {
            "type" : "long"
          },
          "avatarRelativeURL" : {
            "type" : "string"
          },
          "company" : {
            "type" : "string"
          },
          "date" : {
            "type" : "date",
            "format" : "dateOptionalTime"
          },
          "email" : {
            "type" : "string"
          },
          "emailToken" : {
            "type" : "string"
          },
          "emailVerified" : {
            "type" : "boolean"
          },
          "hash" : {
            "type" : "string"
          },
          "managerEmail" : {
            "type" : "string"
          },
          "profile" : {
            "properties" : {
              "firstname" : {
                "type" : "string"
              },
              "lastname" : {
                "type" : "string"
              }
            }
          },
          "resume" : {
            "properties" : {
              "educations" : {
                "properties" : {
                  "annee" : {
                    "type" : "string"
                  },
                  "name" : {
                    "type" : "string"
                  },
                  "school" : {
                    "type" : "string"
                  }
                }
              },
              "experiences" : {
                "properties" : {
                  "company" : {
                    "type" : "string"
                  },
                  "endingDate" : {
                    "type" : "date",
                    "format" : "dateOptionalTime"
                  },
                  "startingDate" : {
                    "type" : "date",
                    "format" : "dateOptionalTime"
                  },
                  "title" : {
                    "type" : "string"
                  }
                }
              },
              "skills" : {
                "properties" : {
                  "category" : {
                    "type" : "string"
                  },
                  "displayedName" : {
                    "type" : "string"
                  },
                  "score" : {
                    "type" : "long"
                  }
                }
              }
            }
          },
          "salt" : {
            "type" : "string"
          }
        }
      },

```

I'm trying to make a query to get the number of skills (in resume.skills.displayedName) the most present.

At this point I succed using this query

```
localhost:9200/index/users/_search?search_type=count -d 'query = {
        'aggs': {
            'skills': {
                'terms': {
                    'field': 'resume.skills.displayedName',
                    'size': 100
                }
            }
        }
    }'

```

This send me the key skills with the counting but my goal at this point is to have a query that would give me the same result + the skill category associated.

In fact, I got my "skills" with 3 field, displayedName, category, score.

So I wish to have the most revelents skills displayedName with the associated category

As an exemple I wanna have :

key: "Shell", "Technical skills", "doc\_count": 501

Hope I've been understandable 🙂

Thank you very much !

Cheers,

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 17, 2016, 12:40pm UTC](https://discuss.elastic.co/t/aggregation-search/53133/2 "2016-06-17T12:40:44Z")

</div>

Hey,

you would need to use an aggregation inside of another aggregation. First you aggregate by `category` and then you aggregate by `displayedName` (or vice versa, depending on what you want).

Check the [terms aggregation docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) for a bit more information and a few examples.

--Alex

---

<div class="post-metadata">

**Author:** ![kZk93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kzk93/32/10379_2.png) [@kZk93](https://discuss.elastic.co/u/kZk93)\
**Post date:** [June 17, 2016, 12:54pm UTC](https://discuss.elastic.co/t/aggregation-search/53133/3 "2016-06-17T12:54:23Z")

</div>

Hello Alex,

First of all, thanks for your reply, I tried to use 2 aggregations like this

{  
'aggs': {  
'skills\_name': {  
'terms': {  
'field': 'resume.skills.displayedName',  
'size': 1000  
}  
}  
},  
'aggs': {  
'skills\_category': {  
'terms': {  
'field': 'resume.skills.category',  
'size': 1000  
}  
}  
}  
}

But it seems that the only aggregation made is the second one, since ES return me the counting for the different categories.

I think I miss understood something around there haha 🙂

Cheers,

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 17, 2016, 2:23pm UTC](https://discuss.elastic.co/t/aggregation-search/53133/4 "2016-06-17T14:23:27Z")

</div>

Hey,

take your time and read the (aggregations chapter]([https://www.elastic.co/guide/en/elasticsearch/guide/current/aggregations.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/aggregations.html)) in the definitive guide, especially the [buckets inside buckets](https://www.elastic.co/guide/en/elasticsearch/guide/current/_buckets_inside_buckets.html) - that shows what I meant.

--Alex

---

<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:** [July 5, 2017, 10:42pm UTC](https://discuss.elastic.co/t/aggregation-search/53133/5 "2017-07-05T22:42:43Z")

</div>


