# Vega: Collecting data from a visualization data table

**URL:** https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724
**Category:** Kibana
**Created:** [January 11, 2021, 1:07pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724 "2021-01-11T13:07:10Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 1:07pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/1 "2021-01-11T13:07:11Z")

</div>

Hello,  
Using a dashboard, I have one visualization which is a data table.  
I am trying to figure out if and how it is possible with Vega to load a specific column from the data table in order to use it with another data source.  
Thank you!

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 1:20pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/2 "2021-01-11T13:20:28Z")

</div>

I don't think using an output of a visualizations in another visualization is possible.

But you can always take in the source data and do the transformations you did in the data table in Vega. Then combine with another data source.

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 1:37pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/3 "2021-01-11T13:37:02Z")

</div>

The transformations that in the data table are based on another filter input (Controls visualization)

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 1:53pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/4 "2021-01-11T13:53:13Z")

</div>

Vega can accept [filter controls](https://www.elastic.co/guide/en/kibana/current/vega-reference.html#vega-queries) also using `%context%: true`.

So if you feed the same data source to Vega and then when that control filter is changed in the dashboard the data going to Vega will be filtered also. Which I think is what you were asking.

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 1:55pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/5 "2021-01-11T13:55:25Z")

</div>

I am using a different data source in Vega.  
The data source I am using in Vega doesn't contain the fields I filter on. That is why I want to collect data from a column in a data table.

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 2:02pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/6 "2021-01-11T14:02:05Z")

</div>

In order to do that you need add the data source to Vega that goes to your data table or control (not sure which one you will need without seeing the data). You can use multiple data sources in Vega.

If you have both data sources going to Vega then you need to do some transformations based on your requirements. Your final data source will now contain the fields required to filter on.

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 2:05pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/7 "2021-01-11T14:05:50Z")

</div>

Then I will have to ask, is it possible to dynamically update transformations in Vega based on applied input in the Controls visualization?

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 2:14pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/8 "2021-01-11T14:14:19Z")

</div>

Correct. Using the link I posted above you can.

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 2:22pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/9 "2021-01-11T14:22:50Z")

</div>

I am sorry, I was not specific enough.  
My intention is:  
When a filter for field 1 is selected,  
then Vega joins data source 1 with data source 2 by field 1  
If a filter for field 2 is selected, then Vega joins data source 1 with data source 2 by the selected field 2.

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 2:40pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/10 "2021-01-11T14:40:43Z")

</div>

When you set a filter on a dashboard that filter can also be use on Vega, as discussed.

But you don't get to know which filter was selected in Vega. Just the end result. So being able to filter off that value wasn't possible unless you were able to determine which filter was passed.

Could be possible if you add a 3rd data source to Vega that feeds your control. Then "somehow" you can figure out which filter was selected based off the results and your new 3rd data source that included all your options.

I'll look at this sometime today to see if there is a better way but as of right now I just can't see it.

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 2:45pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/11 "2021-01-11T14:45:25Z")

</div>

Thank you for the answer.  
You're saying I'm getting the end result in Vega.  
Is it possible to have %context% set to false but still get the results of a specific field to a certain data source?  
Or, have %context% set to true, and get the results on a specific field from the dashboard, but not have it affect the Vega visualization?

Also, can you please elaborate on the 3rd data source solution? How would a data source feed the control?

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 2:54pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/12 "2021-01-11T14:54:08Z")

</div>

> Is it possible to have %context% set to false but still get the results of a specific field to a certain data source?

Not from the Dashboard. You would need to add another data source to Vega to get that value.

> Or, have %context% set to true, and get the results on a specific field from the dashboard, but not have it affect the Vega visualization?

You can't pass data from Dashboard to Vega.

> Also, can you please elaborate on the 3rd data source solution? How would a data source feed the control?

In Vega, Data is an array and you can make as many data sources as you want (I think).

It might be helpful to open Vega and then Inspect your Request and Response without a filter. Then add a filter in and look at it. The response is what you have access to for data.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/9/299b8ae748b42db8fde5d1bff59c490f644ce876.jpeg)

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 3:04pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/13 "2021-01-11T15:04:47Z")

</div>

Thank you for the response.

> Not from the Dashboard. You would need to add another data source to Vega to get that value.

Assuming I go this way, how do I get the value?  
Let's say, I am searching for top hits of field 1. By default, it shouldn't be a problem.  
How do I get the top hits of field 1, after applying a filter to the dashboard, without it affecting the Vega visualization?

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 3:09pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/14 "2021-01-11T15:09:07Z")

</div>

> It might be helpful to open Vega and then Inspect your Request and Response without a filter. Then add a filter in and look at it. The response is what you have access to for data.

I understand that in this use case it is only for a specific filter, and not a dynamic filter based on user input? Would that be possible?

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 3:15pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/15 "2021-01-11T15:15:42Z")

</div>

> I understand that in this use case it is only for a specific filter, and not a dynamic filter based on user input? Would that be possible?

The static filter is just simulating what a dynamic filter would look like in the request/response. So it would be the same result.

> How do I get the top hits of field 1, after applying a filter to the dashboard, without it affecting the Vega visualization?

If you made a second data source in Vega to get this data it won't effect anything at all unless you want it to. Your main data source is what drives your visualization from what it sounds like. Your new data source would just be to enhance or transform it.

I am not sure if this method would even work, never tried. I think though that all your issues would be solved if we actually made the filter data available in Vega so users can have more control.

---

<div class="post-metadata">

### Author: ![nikita\_zaliven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikita_zaliven/32/78368_2.png) [@nikita\_zaliven](https://discuss.elastic.co/u/nikita_zaliven)
#### Post date: [January 11, 2021, 3:19pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/16 "2021-01-11T15:19:04Z")

</div>

Makes sense, thanks.  
In this case, how can I dynamically add the filter used in the dashboard to my data source in Vega?

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 3:23pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/17 "2021-01-11T15:23:39Z")

</div>

I do not know that it's possible. But I do know you have to have that data source that controls that filter also brought into Vega.

Then through [Vega transformations](https://vega.github.io/vega/docs/transforms/) combine the 2 data sources and attempt to figure out which filter was selected. I don't know if this is possible, just the only idea I have left.

---

<div class="post-metadata">

### Author: ![nikitiki](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@nikitiki](https://discuss.elastic.co/u/nikitiki)
#### Post date: [January 11, 2021, 3:29pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/18 "2021-01-11T15:29:43Z")

</div>

> But I do know you have to have that data source that controls that filter also brought into Vega.

How do I bring that data source into Vega?

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 11, 2021, 3:37pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/19 "2021-01-11T15:37:05Z")

</div>

There is an example on the [documentation](https://www.elastic.co/guide/en/kibana/7.x/vega-reference.html#vega-queries). Also check out the [Vega documentation](https://vega.github.io/vega/docs/data/).

I was assuming you already was doing this so knew how. Data is an array also so you can bring in multiple data sets then reference them by name.

```auto
data: [
 {
  "name": "NAME"
 },
 {
  "name": "NAME"
 }
]

```

---

<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 8, 2021, 3:37pm UTC](https://discuss.elastic.co/t/vega-collecting-data-from-a-visualization-data-table/260724/20 "2021-02-08T15:37:47Z")

</div>

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