# Manipulating the output of term aggregation

**URL:** <https://discuss.elastic.co/t/manipulating-the-output-of-term-aggregation/208525>\
**Category:** Elasticsearch\
**Created:** [November 19, 2019, 2:26pm UTC](https://discuss.elastic.co/t/manipulating-the-output-of-term-aggregation/208525 "2019-11-19T14:26:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![poomdla\_sai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/poomdla_sai/32/57959_2.png) [@poomdla\_sai](https://discuss.elastic.co/u/poomdla_sai)\
**Post date:** [November 19, 2019, 2:26pm UTC](https://discuss.elastic.co/t/manipulating-the-output-of-term-aggregation/208525/1 "2019-11-19T14:26:39Z")

</div>

After performing a term aggregation query, the output consists of different buckets where each bucket consists of doc\_count. Is it possible to get the list of doc\_count of all the buckets and manipulate their values.  
//{  
...  
"aggregations" : {  
"genres" : {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets" : [  
{  
"key" : "electronic",  
"doc\_count" : 6  
},  
{  
"key" : "rock",  
"doc\_count" : 3  
},  
{  
"key" : "jazz",  
"doc\_count" : 2  
}  
]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 21, 2019, 12:00pm UTC](https://discuss.elastic.co/t/manipulating-the-output-of-term-aggregation/208525/2 "2019-11-21T12:00:39Z")

</div>

That sounds like a task to do on the client side if you want to change the JSON structure after that. There is no way to modify a JSON response in an Elasticsearch query, you can only filter out certain parts, but not change its structure.

---

<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:** [December 19, 2019, 12:00pm UTC](https://discuss.elastic.co/t/manipulating-the-output-of-term-aggregation/208525/3 "2019-12-19T12:00:41Z")

</div>

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