# Can't get empty buckets with nested, terms aggregation

**URL:** <https://discuss.elastic.co/t/cant-get-empty-buckets-with-nested-terms-aggregation/64789>\
**Category:** Elasticsearch\
**Created:** [November 3, 2016, 1:52am UTC](https://discuss.elastic.co/t/cant-get-empty-buckets-with-nested-terms-aggregation/64789 "2016-11-03T01:52:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seongjun\_Kang](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Seongjun\_Kang](https://discuss.elastic.co/u/Seongjun_Kang)\
**Post date:** [November 3, 2016, 1:52am UTC](https://discuss.elastic.co/t/cant-get-empty-buckets-with-nested-terms-aggregation/64789/1 "2016-11-03T01:52:49Z")

</div>

Elasticsearch version: 2.3.1

Description of the problem including expected versus actual behavior:  
Hi I'm trying to use nested, terms aggregation including empty bucket as search result.  
Problem is when I send nested, terms aggregation query with min\_doc\_count: 0 option, I can't get empty buckets. But when I send not nested terms aggregation, result is same as I expected (it includes empty buckets with value of null or 0).

For example below works well (without nested) :

```
{
  "size":0,
  "query":{
    "bool":{  
      "filter":[
        {
          "range":{
            "date":{
              "time_zone":"+09:00",
              "format":"yyyy-MM-dd",
              "gte":"2016-11-01||/d",
              "lt":"2016-11-01||+1d/d"
            }
          }
        }
      ]
    }
  },
  "aggs":{  
    "item_name":{  
      "terms":{  
        "field":"name",
        "min_doc_count":0,
        "size":0
      },
      "aggs":{  
        "price_sum":{  
          "sum":{  
            "field":"price"
          }
        }
      }
    }
  }
}

```

Above query returns below:

```
{  
  "took":1,
  "timed_out":false,
  "_shards":{  
    "total":1,
    "successful":1,
    "failed":0
  },
  "hits":{  
    "total":0,
    "max_score":0,
    "hits":[]
  },
  "aggregations":{  
    "name":{  
      "doc_count_error_upper_bound":0,
      "sum_other_doc_count":0,
      "buckets":[  
        {  
          "key":"key1",
          "doc_count":0,
          "price_sum":{  
            "value":0
          }
        },
        {  
          "key":"key2",
          "doc_count":0,
          "price_sum":{  
            "value":0
          }
        }
      ]
    }
  }
}

```

Now below query is what I'd like to send (aggregation with nested, item.property):

```
{  
  "size":0,
  "query":{  
    "bool":{  
      "filter":[  
        {  
          "range":{  
            "date":{  
              "time_zone":"+09:00",
              "format":"yyyy-MM-dd",
              "gte":"2016-11-01||/d",
              "lt":"2016-11-01||+1d/d"
            }
          }
        }
      ]
    }
  },
  "aggs":{  
    "lines":{  
      "nested":{  
        "path":"property"
      },
      "aggs":{  
        "property_types":{  
          "terms":{  
            "field":"property.type",
            "size":0
          },
          "aggs":{  
            "some_value_of_property_sum":{  
              "sum":{  
                "field":"property.some_value"
              }
            }
          }
        }
      }
    }
  }
}

```

But it returns below :

```
{  
  "took":1,
  "timed_out":false,
  "_shards":{  
    "total":1,
    "successful":1,
    "failed":0
  },
  "hits":{  
    "total":0,
    "max_score":0,
    "hits":[]
  },
  "aggregations":{  
    "property_types":{  
      "doc_count":0,
      "some_value_of_property_sum":{  
        "doc_count_error_upper_bound":0,
        "sum_other_doc_count":0,
        "buckets":[]
      }
    }
  }
}

```

while I expect below :

```
"buckets":[  
  {
    "key":"key1",
    "doc_count":0,
    "some_value_of_property_sum":{
      "value":0
    }
  },
  {
    "key":"key2",
    "doc_count":0,
    "some_value_of_property_sum":{
      "value":0
    }
  }
]

```

What am I doing wrong?

---

<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:07pm UTC](https://discuss.elastic.co/t/cant-get-empty-buckets-with-nested-terms-aggregation/64789/2 "2017-07-05T22:07:06Z")

</div>


