Elastic Search Nested Aggregations

Hi
i am new to elastic search Query and aggregation.
I have a nested document with the following mapping

PUT /company
{
"mappings": {
"data": {
"properties": {
"deptId": {
"type": "keyword"
},
"deptName": {
"type": "keyword"
},
"employee": {
"type": "nested",
"properties": {
"empId": {
"type": "keyword"
},
"empName": {
"type": "text"
},
"salary": {
"type": "float"
}}
} } } }}

I have sample data like

PUT company/data/1
{
"deptId":"1",
"deptName":"HR",
"employee": [
{
"empId": "1",
"empName": "John",
"salary":"1000"
},
{
"empId": "2",
"empName": "Will",
"salary":"2000"
}
]
}

PUT company/data/2
{
"deptId":"2",
"deptName":"FINANCE",
"employee": [
{
"empId": "1",
"empName": "John",
"salary":"1000"
}]
}

PUT company/data/3
{
"deptId":"3",
"deptName":"FINANCE",
"employee": [
{
"empId": "1",
"empName": "John",
"salary":"1000"
},
{
"empId": "2",
"empName": "Will",
"salary":"2000"
},
{
"empId": "3",
"empName": "Mark",
"salary":"4000"
}]
}

I would like assisting in creating a Query to

  1. Department with the maximum Employees
  2. Employee that is present in most departments

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