# Vega: Access to data

**URL:** https://discuss.elastic.co/t/vega-access-to-data/128748
**Category:** Kibana
**Created:** [April 19, 2018, 4:51pm UTC](https://discuss.elastic.co/t/vega-access-to-data/128748 "2018-04-19T16:51:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MimmiXYZ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mimmixyz/32/30206_2.png) [@MimmiXYZ](https://discuss.elastic.co/u/MimmiXYZ)
#### Post date: [April 19, 2018, 4:51pm UTC](https://discuss.elastic.co/t/vega-access-to-data/128748/1 "2018-04-19T16:51:36Z")

</div>

Hi everyone,

I'm trying to create a Vega visualization. Here is a short extract of the code:

```auto
...
   "data": [
        {
          "name": "ttchanges",
          "url": {
            "%context%": true,
            "%timefield%": "changedate",
            "index": "ttableschanges_*",
            "body": {
              "aggs": {
                "tb": {
                  "date_histogram": {
                    "field": "changedate",
                    "interval": "1d"
                  },
                  "aggs": {
                    "bucket2": {
                      "terms": {
                        "field": "techtablename.keyword",
                        "size": 40,
                        "order": {
                          "_count": "desc"
                        },
                        "valueType": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "format": {
            "property": "aggregations.tb.buckets"
          },

          "transform": [
            {
              "type": "formula",
              "as": "ch_date",
              "expr": "datetime(datum.key)"
            }
          ]
        }
      ],
      "scales": [
        {
          "name": "xscale",
          "type": "time",
          "range": "width",
          "round": true,
          "domain": {
            "data": "ttchanges",
            "field": "ch_date"
          }
        },
        {
          "name": "yscale",
          "type": "band",
          "range": "height",
          "round": true,
          "padding": 0,
          "domain": {
            "data": "ttchanges",
            "field": "*datum*"
          }
        }
      ] ...

```

Now my question. In the yscale I would like to access a field (where it says datum right now) from the second aggregation which is called _bucket2_. How do I do this? I was able to access the key with datum.key to transform it to a proper date, but don't know how to go from there... tried datum.bucket2['xyz'] and couple of other things, but nothing works....  
Would appreciate any help/hint!

Thank you!

---

<div class="post-metadata">

### Author: ![MimmiXYZ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mimmixyz/32/30206_2.png) [@MimmiXYZ](https://discuss.elastic.co/u/MimmiXYZ)
#### Post date: [April 20, 2018, 12:20pm UTC](https://discuss.elastic.co/t/vega-access-to-data/128748/2 "2018-04-20T12:20:13Z")

</div>

Here's some more information  
This is what the data looks like in the debug view. I'd like to access the bucket2 array in each data point.  
Not sure whether I have to format my data differently. Currently I'm using

```auto
"format": {
            "property": "aggregations.tb.buckets"
          },

```

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/9/0/9086ee2eaab9d752d32bf2f95286e8d85139afcb.JPG)

As "bucket2" is an array within the current "datum" data point, I guess my question is, how do I access an array in a datapoint?

---

<div class="post-metadata">

### Author: ![emil.mirzayev](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@emil.mirzayev](https://discuss.elastic.co/u/emil.mirzayev)
#### Post date: [May 7, 2018, 9:53am UTC](https://discuss.elastic.co/t/vega-access-to-data/128748/3 "2018-05-07T09:53:27Z")

</div>

Hi @MimmiXYZ,

you can access `bucket2` via its own name, you do not have to use datum.bucket2 in this case, as the whole datum includes this field. So, you can use:

```auto
{
          "name": "yscale",
          "type": "band",
          "range": "height",
          "round": true,
          "padding": 0,
          "domain": {
            "data": "ttchanges",
            "field": "bucket2.some_nested_field.some_other_field"
          }
        }
´´´
```

---

<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 4, 2018, 10:08am UTC](https://discuss.elastic.co/t/vega-access-to-data/128748/4 "2018-06-04T10:08:54Z")

</div>

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