# Aggregating tags

**URL:** <https://discuss.elastic.co/t/aggregating-tags/48795>\
**Category:** Elasticsearch\
**Created:** [April 29, 2016, 10:36am UTC](https://discuss.elastic.co/t/aggregating-tags/48795 "2016-04-29T10:36:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandhya\_Rathinapandi](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Sandhya\_Rathinapandi](https://discuss.elastic.co/u/Sandhya_Rathinapandi)\
**Post date:** [April 29, 2016, 10:36am UTC](https://discuss.elastic.co/t/aggregating-tags/48795/1 "2016-04-29T10:36:57Z")

</div>

Hi,

we are using a index where we have 3 fields type, fileinfo and timestamp.

In the fileinfo field I will be having a json String where there will count of different number of file formats.

example:  
{"items":[{"type":"xml","size":0.020,"filecount":80},{"type":"pdf","size":104.245,"filecount":20}]}

Now my problem is I want to set the sum of the size of all the pdf files. similary for other types of files

Is there any way to do this.

Thanks,  
Sandhya

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 29, 2016, 9:29pm UTC](https://discuss.elastic.co/t/aggregating-tags/48795/2 "2016-04-29T21:29:21Z")

</div>

Take a look at scripted metric aggregations. You could do a terms aggregation on type, and in your script sum the size field.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html)

---

<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:55pm UTC](https://discuss.elastic.co/t/aggregating-tags/48795/3 "2017-07-05T22:55:09Z")

</div>

Closed on July 5, 2017, 10:55pm UTC


