# How to remove empty buckets aggregation multi field

**URL:** <https://discuss.elastic.co/t/how-to-remove-empty-buckets-aggregation-multi-field/59755>\
**Category:** Elasticsearch\
**Created:** [September 4, 2016, 10:50am UTC](https://discuss.elastic.co/t/how-to-remove-empty-buckets-aggregation-multi-field/59755 "2016-09-04T10:50:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dannyxu](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@dannyxu](https://discuss.elastic.co/u/dannyxu)\
**Post date:** [September 4, 2016, 10:50am UTC](https://discuss.elastic.co/t/how-to-remove-empty-buckets-aggregation-multi-field/59755/1 "2016-09-04T10:50:50Z")

</div>

in es 2.3.3, aggregation multi field using following query string ,  
GET /myindex/mysubtype/\_search  
{  
"size": 0,  
"query": {  
"range": {  
"longdate.dateval": {  
"gte": "20160101000000",  
"lte": "20160601000000"  
}  
}  
},  
"aggs": {  
"aggs1": {  
"terms": {  
"field": "\_parent",  
"size": 5  
},  
"aggs": {  
"aggs2": {  
"terms": {  
"field": "cardno.raw",  
"min\_doc\_count": 51  
}  
}  
}  
}  
}  
}

the following is result,  
{  
"took": 668,  
"timed\_out": false,  
"\_shards": {  
"total": 6,  
"successful": 6,  
"failed": 0  
},  
"hits": {  
"total": 316275,  
"max\_score": 0,  
"hits": []  
},  
"aggregations": {  
"aggs1": {  
"doc\_count\_error\_upper\_bound": 99,  
"sum\_other\_doc\_count": 315773,  
"buckets": [  
{  
"key": "13304111973020",  
"doc\_count": 144,  
"aggs2": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 18,  
"buckets": []  
}  
},  
{  
"key": "13411261971",  
"doc\_count": 115,  
"aggs2": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": []  
}  
},  
{  
"key": "15321261989051",  
"doc\_count": 85,  
"aggs2": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "1370402197",  
"doc\_count": 85  
}  
]  
}  
},  
{  
"key": "1330483199007",  
"doc\_count": 82,  
"aggs2": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": []  
}  
},  
{  
"key": "1511521604119",  
"doc\_count": 76,  
"aggs2": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "1512527640822",  
"doc\_count": 76  
}  
]  
}  
}  
]  
}  
}  
}

the result exists empty buckets , how to remove it. thanks!

---

<div class="post-metadata">

**Author:** ![thn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thn/32/8061_2.png) [@thn](https://discuss.elastic.co/u/thn)\
**Post date:** [September 4, 2016, 12:39pm UTC](https://discuss.elastic.co/t/how-to-remove-empty-buckets-aggregation-multi-field/59755/2 "2016-09-04T12:39:02Z")

</div>

You need to clean your data before indexing it.... if a field has no value, and you use Gson for example, initialize the field with null, when converting to JSON, Gson will skip this field. If you are not using Gson, you have to do that yourself before sending the JSON data to ES for indexing.

---

<div class="post-metadata">

**Author:** ![dannyxu](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@dannyxu](https://discuss.elastic.co/u/dannyxu)\
**Post date:** [September 4, 2016, 1:49pm UTC](https://discuss.elastic.co/t/how-to-remove-empty-buckets-aggregation-multi-field/59755/3 "2016-09-04T13:49:51Z")

</div>

thanks for reply.  
all aggeration field has values,but when count less than some value, the buckets turn empty. only greater than some value the buckets not empty.

---

<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:22pm UTC](https://discuss.elastic.co/t/how-to-remove-empty-buckets-aggregation-multi-field/59755/4 "2017-07-05T22:22:39Z")

</div>


