# Terms Aggregating over array elements and correlating data from a second array

**URL:** <https://discuss.elastic.co/t/terms-aggregating-over-array-elements-and-correlating-data-from-a-second-array/231156>\
**Category:** Kibana\
**Created:** [May 5, 2020, 1:08pm UTC](https://discuss.elastic.co/t/terms-aggregating-over-array-elements-and-correlating-data-from-a-second-array/231156 "2020-05-05T13:08:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![svbernem](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@svbernem](https://discuss.elastic.co/u/svbernem)\
**Post date:** [May 5, 2020, 1:08pm UTC](https://discuss.elastic.co/t/terms-aggregating-over-array-elements-and-correlating-data-from-a-second-array/231156/1 "2020-05-05T13:08:40Z")

</div>

Hi,  
I have data in the following form:

```auto
doc1: {"names": ["n1","n2","n3"], "data_points":[0,1,2]}
doc2: {"names": ["n1","n2","n3"], "data_points":[1,2,3]}
doc3: {"names": ["n1","n2","n3"], "data_points":[2,3,4]}

```

Which corresponds to the series n1:0-1-2, n2:1-2-3 and n3:2-3-4. They are basically completely separate functions. I want to plot the data\_points over time, one plot for each name, but all in a single visualization. How can I achieve this in a Kibana visualization? If the datapoints would be one per doc like so: `{"name": "n1", "data_point":0}`, I know I could just use the Terms aggregation, but that doesn't seem to work in this case. After some search, I discovered that maybe the composite aggregation might help me in this case, but it doesn't seem to be available in Kibana(?).

I can not restructure the data to have one datapoint per doc, but I could restructure it like this, if that helps:

```auto
 doc1: {"touples": [{"name": "n1", "data_point":0},{"name": "n2", "data_point":1},{"name": "n3", "data_point":2}]}

```

---

<div class="post-metadata">

**Author:** ![dosant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dosant/32/64489_2.png) [@dosant](https://discuss.elastic.co/u/dosant)\
**Post date:** [May 6, 2020, 3:11pm UTC](https://discuss.elastic.co/t/terms-aggregating-over-array-elements-and-correlating-data-from-a-second-array/231156/2 "2020-05-06T15:11:19Z")

</div>

Hi @svbernem,

> After some search, I discovered that maybe the composite aggregation might help me in this case, but it doesn't seem to be available in Kibana

I am not an expert on this matter, but I think you could try to use Vega visualisation for composite aggregation.

Some details on Vega:

- Blog: [Custom Vega Visualizations in Kibana 6.2 | Elastic Blog](https://www.elastic.co/blog/custom-vega-visualizations-in-kibana)
- Webinar: [Custom Kibana Visualizations with Vega | Elastic Videos](https://www.elastic.co/webinars/creating-custom-kibana-visualizations-with-vega-plugin)
- And there is an example with composite agg: [Vega Webinar - area chart from multivariable composite aggregation · GitHub](https://gist.github.com/nyurik/c08f4e791a6ef0393b8aab72bbdb8d90)

Hope this is helpful

---

<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:** [June 3, 2020, 3:16pm UTC](https://discuss.elastic.co/t/terms-aggregating-over-array-elements-and-correlating-data-from-a-second-array/231156/3 "2020-06-03T15:16:49Z")

</div>

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