# Aggregate multiple records to single chart

**URL:** <https://discuss.elastic.co/t/aggregate-multiple-records-to-single-chart/86561>\
**Category:** Kibana\
**Created:** [May 21, 2017, 9:56am UTC](https://discuss.elastic.co/t/aggregate-multiple-records-to-single-chart/86561 "2017-05-21T09:56:14Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [July 27, 2017, 7:13pm UTC](https://discuss.elastic.co/t/aggregate-multiple-records-to-single-chart/86561/23 "2017-07-27T19:13:09Z")

</div>

Hi Avivc,

You still haven't posted example data such that I can understand your question, so I'm making some up. In the Dev Console I did this;

```auto
POST my_index/defect/
{
      "Project._refObjectName": "value1"
}

POST my_index/defect/
{
      "Project._refObjectName": "value2"
}

POST my_index/defect/
{
      "Project._refObjectName": "value3"
}

POST my_index/defect/
{
      "Project._refObjectName": "value4"
}

POST my_index/defect/
{
      "Project._refObjectName": "value5"
}

POST my_index/defect/
{
      "Project._refObjectName": "value1"
}

POST my_index/defect/
{
      "Project._refObjectName": "value2"
}

```

Then I made this scripted field named `oneOrTwo`;

```auto
if (doc['Project._refObjectName.keyword'].value == 'value1' || doc['Project._refObjectName.keyword'].value == 'value2') {
return "value1or2";
} else {
return doc['Project._refObjectName.keyword'].value
}

```

And then I made this visualization which shows a terms aggregation on that scripted field. Since there are 2 docs with `value1` and 2 docs with `value2` the chart shows a count of 4 docs with the value of `value1or2`;

 ![](https://us1.discourse-cdn.com/elastic/original/3X/5/3/53353129f179c534ec29c3f8bc56045b0286acbd.png)

I can also create the same chart without using the scripted field by using a Filter aggregation (the first filter is `Project._refObjectName.keyword=value1 OR Project._refObjectName.keyword=value2`

 ![](https://us1.discourse-cdn.com/elastic/original/3X/b/1/b1dfbbdb6c494ebf34fcaaf66cb82a97461067b6.png)

---

_[View the full topic](https://discuss.elastic.co/t/aggregate-multiple-records-to-single-chart/86561)._
