essuraj
6/28/2018 - 6:08 AM

Subaggregation

{
  "_source": [
    "countrycode",
    "city"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "countrycode": "IN"
          }
        },
        {
          "term": {
            "city": "Hyderabad"
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "phones": ""
          }
        }
      ],
      "should": []
    }
  },
  "from": 0,
  "size": 0,
  "sort": [],
  "aggs": {
    "citys": {
      "terms": {
        "field": "city",
        "size": 20
      },
      "aggs": {
        "zipcodes": {
          "terms": {
            "field": "zipcode"
          },
          "aggs": {
            "phoness": {
              "terms": {
                "field": "phones"
              },
              "aggs": {
                "hotels": {
                  "terms": {
                    "field": "hotelname"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}