# Tag cloud based on sum of fields

**URL:** <https://discuss.elastic.co/t/tag-cloud-based-on-sum-of-fields/216584>\
**Category:** Kibana\
**Created:** [January 26, 2020, 10:22pm UTC](https://discuss.elastic.co/t/tag-cloud-based-on-sum-of-fields/216584 "2020-01-26T22:22:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcalder](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@bcalder](https://discuss.elastic.co/u/bcalder)\
**Post date:** [January 26, 2020, 10:22pm UTC](https://discuss.elastic.co/t/tag-cloud-based-on-sum-of-fields/216584/1 "2020-01-26T22:22:56Z")

</div>

I'm just starting with Kibana and want to create a Tag Cloud. The index I’m using stores documents that are posted each hour and contain counts from up to 200 counters. A sample of the data is as follows:

> ```
> {
> "_index": "counters",
> "_type": "_doc",
> "_id": "Q7HU428BKC2y1k9Xjhvc",
> "_score": 1.0,
> "_source": {
> "countDate": "2020-01-17T00:00:00",
> "counters": {
> "counter_a": 25,
> "counter_b": 12,
> "counter_c": 7,
> "total": 150
> }
> }
> }
> 
> ```

I would like the tag cloud to show the counter names (counter\_a, counter\_b, etc) in proportion to a summation of the counts from all the documents – i.e. the sum of counter\_a across all documents would be 1,100, the sum of counter\_b would be 650 & the sum of counter\_c would be 330. Therefore the font size of counter\_a would be the largest while counter\_c would be the smallest and counter\_b would be in between.

Is what I’m asking doable? If so, how would I get started? I do have the flexibility of re-creating the index with a different mapping if required to achieve my goal.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [January 28, 2020, 1:55pm UTC](https://discuss.elastic.co/t/tag-cloud-based-on-sum-of-fields/216584/2 "2020-01-28T13:55:51Z")

</div>

Hi @bcalder,

If you would ingest your counter values as separate documents like this:  
`{ "countDate": "2020-01-17T00:00:00", "counterName": "counter_a", "counterValue": 25 }` ,  
`{ "countDate": "2020-01-17T00:00:00", "counterName": "counter_b", "counterValue": 12 }` ,  
`{ "countDate": "2020-01-17T00:00:00", "counterName": "counter_c", "counterValue": 7 }`,  
`{ "countDate": "2020-01-17T00:00:00", "counterName": "total", "counterValue": 150 }`

Then you should be able to get this visualization by using a `Terms` aggregation on the `counterName` field for the Tags and a `Sum` aggregation on the `counterValue` field for the Tag size.

---

<div class="post-metadata">

**Author:** ![bcalder](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@bcalder](https://discuss.elastic.co/u/bcalder)\
**Post date:** [January 28, 2020, 9:42pm UTC](https://discuss.elastic.co/t/tag-cloud-based-on-sum-of-fields/216584/3 "2020-01-28T21:42:19Z")

</div>

I refactored my custom NiFi processor to push documents to Elasticsearch using the mapping you recommended and the Tag Cloud rendered perfectly! This revised mapping helps a lot with other visualizations I've been working on.

---

<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:** [February 25, 2020, 9:42pm UTC](https://discuss.elastic.co/t/tag-cloud-based-on-sum-of-fields/216584/4 "2020-02-25T21:42:21Z")

</div>

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