title: adding subaggregations in Elasticsearch
body: <p>I am trying to retrieve data from Elasticsearch with the following structure:</p>
  
  <pre><code>"hits":[
     { _index...
       _type....
       _score...
       "_source": {
                    "language": "english",
                    "timeDic": {
                                 "date": "Friday",
                                 "time": {
                                           "timeofday": "15:23"
                                          }
                                }
                   }
     }       
     { _index...
       _type....
       _score...
       "_source": {
                    "language": "spanish",
                    "timeDic": {
                                 "date": "Friday",
                                 "time": {
                                           "timeofday": "18:23"
                                          }
                                }
                   }
     }
     { _index...
       _type....
       _score...
       "_source": {
                    "language": "english",
                    "timeDic": {
                                 "date": "Saturday",
                                 "time": {
                                           "timeofday": "08:23"
                                          }
                                }
                   }
     }
    ...
   }
  ]
  </code></pre>
  
  <p>The fields I want to obtain are date and timeofday.</p>
  
  <p>I have tried to obtain the data with the following code.</p>
  
  <pre><code>    'timeDic': {
         terms: {
               field: 'date.keyword',
               order: {
                    _count: "desc"
                 }
               },
               aggs: {
                    'time': {
                          terms: {
                               field: "timeofday.keyword",
                                order: {
                                     _count: "desc"
                                     }
                            }
                    }
                }
  </code></pre>
  
  <p>The thing is that the bucket of the field hour1 is empty, it returns this:</p>
  
  <pre><code>timeDic: {doc_count_error_upper_bound: 0, sum_other_doc_count: 0, 
  …}
     buckets: [{key: "Friday", doc_count: 208,…}, {key: "Sunday", 
     doc_count: 207,…},…]
       0: {key: "Friday", doc_count: 208,…}
        doc_count: 208
        key: "Friday"
          time: {doc_count_error_upper_bound: 0, 
           sum_other_doc_count: 0, buckets: []}
              buckets: []
              doc_count_error_upper_bound: 0
              sum_other_doc_count: 0
  </code></pre>
  
  <p>and the answer I'm looking for is something like this.</p>
  
  <pre><code>timeDic: {doc_count_error_upper_bound: 0, sum_other_doc_count: 0, 
  …}
     buckets: [{key: "Friday", doc_count: 208,…}, {key: "Sunday", 
     doc_count: 207,…},…]
       0: {key: "Friday", doc_count: 208,…}
        doc_count: 208
        key: "Friday"
          time: {doc_count_error_upper_bound: 0, 
           sum_other_doc_count: 0, buckets: []}
              buckets: [key: "15:23", doc_count: whatever they are,…}]
                      doc_count: whatever they are
                      key: "15:23"
                      doc_count_error_upper_bound: 0
                      sum_other_doc_count: 0
  </code></pre>
  
  <p>Of course I have read the Elasticsearch documentation and other comments but so far I have not found anything...</p>