# Vega Array to Data Table

**URL:** <https://discuss.elastic.co/t/vega-array-to-data-table/203475>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [October 14, 2019, 2:05pm UTC](https://discuss.elastic.co/t/vega-array-to-data-table/203475 "2019-10-14T14:05:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![comijo](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@comijo](https://discuss.elastic.co/u/comijo)\
**Post date:** [October 14, 2019, 2:05pm UTC](https://discuss.elastic.co/t/vega-array-to-data-table/203475/1 "2019-10-14T14:05:52Z")

</div>

Hi there,

Thanks for being on this topic. I hope it will help others

Here is what I'm trying to achieve:  
The data source of my data is from elasticsearch and the data format is like that:  
[timestamp: data, metric11:number, metric12: number, metric21:number, metric22: number]

metric11 and metric12 are associated: value11(0) is asociated with value12(0)  
Same for metric21 and metric22

I'd like to create a table like that, showing only the latest value (last timestamp) and refreshing everytime it updates

metric11 (sorted) | metric 12 || metric 21 (sorted) | metric22  
value11(0) | value12(0)|| value21(0) | value22(0)  
value11(1) | value12(1)|| value21(1) | value22(1)  
value11(2) | value12(2)|| value21(2) | value22(2)

I'm really struggle to understand how I can do that.

Have you already done something similar ? Any idea ?

thx vm for reading and for your help

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [October 17, 2019, 7:39pm UTC](https://discuss.elastic.co/t/vega-array-to-data-table/203475/2 "2019-10-17T19:39:18Z")

</div>

It might help if you actually showed an example document you have in Elasticsearch.

It sounds like you might be wanting to use the Top Hits aggregation, have you given that a try?

---

<div class="post-metadata">

**Author:** ![comijo](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@comijo](https://discuss.elastic.co/u/comijo)\
**Post date:** [October 17, 2019, 8:02pm UTC](https://discuss.elastic.co/t/vega-array-to-data-table/203475/3 "2019-10-17T20:02:27Z")

</div>

Hi Lukas, thank you very much for responding !  
Here is an example of the data (simplified):  
{  
"\_index": "mydata",  
"\_type": "\_doc",  
"\_id": "-JRJ220BzFM5gRVLQt0q",  
"\_version": 1,  
"\_score": null,  
"\_source": {  
"timestamp": 1571342073684,  
"name": "sample1",  
"metric1": [  
{  
"rank": 1,  
"value1": "0.021934",  
"value2": "0.06",  
"source": "google"  
},]  
"metric2": [  
{  
"rank": 1,  
"value1": "0.02193913",  
"value2": "0.43918947",  
"source": "twitter"  
}]  
},  
"sort": [  
1571342073684  
]  
}

And I'd like to have:  
metric1 .................................. | metric2...............................................|  
value1 .... | value2 .| source |value1 ........ | value2 ........| source |  
0.021934 | 0.06..... | google |0.02193913 | 0.43918947 | twitter |

Or even if the table metric1 and metric2 are separated that would do the job

Top Hits would be to get only the last value, but I don't understand how I can get this result (probably with the flatten transformation).

Does this sample is of any help ?

---

<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:** [November 14, 2019, 8:02pm UTC](https://discuss.elastic.co/t/vega-array-to-data-table/203475/4 "2019-11-14T20:02:27Z")

</div>

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