Aggregation search

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 :slight_smile:

Thank you very much !

Cheers,

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 for a bit more information and a few examples.

--Alex

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 :slight_smile:

Cheers,

Hey,

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

--Alex