# Accessing a flattened field in Kibana-VegaLite

**URL:** https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253
**Category:** Kibana
**Tags:** vega
**Created:** [July 21, 2022, 8:44am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253 "2022-07-21T08:44:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![InesCM](https://avatars.discourse-cdn.com/v4/letter/i/9d8465/32.png) [@InesCM](https://discuss.elastic.co/u/InesCM)
#### Post date: [July 21, 2022, 8:44am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/1 "2022-07-21T08:44:21Z")

</div>

Hi there!  
I'm successfully being able to flatten a nested field in VegaLite (several nestings, by the way).  
However, even if the flattened field is recognized, I get undefined when accessing the fields.  
Any ideas why this might happen?

I'm doing this:

```auto
  "transform": [
    {"calculate": "datum.frequencies.freqs.buckets", "as": "F"},
    {"flatten": ["F"]},
    {"flatten": ["F.rangos.buckets"]}
  ],
  "mark": "point",
  "encoding": {"x": {"field": "F.rangos.buckets.key"}, "y": {"field": "F.rangos.buckets.doc_count"}}
}

```

But even if I can properly see the flattened F.rangos.buckets, I still get undefined for key and doc\_count:

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

No clues why this is happening, as I can properly access any other F fields with no issues.

Thanks a lot in advance for your help!

My whole code below, in case it helps:

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {
        "key" : "es",
        "doc_count" : 138903384,
        "frequencies" : {
          "doc_count" : 1403494559,
          "freqs" : {
            "buckets" : [
              {
                "key": 314000,
                "doc_count": 59767102,
                "rangos": {
                  "buckets": [
                    {"key": "1.0-29.0", "from": 1, "to": 29, "doc_count": 104},
                    {"key": "30.0-34.0", "from": 30, "to": 34, "doc_count": 681}
                  ]
                }
              },
              {
                "key": 266000,
                "doc_count": 59764524,
                "rangos": {
                  "buckets": [
                    {"key": "1.0-29.0", "from": 1, "to": 29, "doc_count": 509},
                    {"key": "30.0-34.0", "from": 30, "to": 34, "doc_count": 3201}
                  ]
                }
              }
            ]
          }
        }
      }  
    ]
  },
  "transform": [
    {"calculate": "datum.frequencies.freqs.buckets", "as": "F"},
    {"flatten": ["F"]},
    {"flatten": ["F.rangos.buckets"]}
  ],
  "mark": "point",
  "encoding": {"x": {"field": "F.rangos.buckets.key"}, "y": {"field": "F.rangos.buckets.doc_count"}}
}

```

---

<div class="post-metadata">

### Author: ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)
#### Post date: [July 21, 2022, 3:38pm UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/2 "2022-07-21T15:38:50Z")

</div>

How about calculate "F.rangos.buckets" before flatten the field?

---

<div class="post-metadata">

### Author: ![InesCM](https://avatars.discourse-cdn.com/v4/letter/i/9d8465/32.png) [@InesCM](https://discuss.elastic.co/u/InesCM)
#### Post date: [July 22, 2022, 5:45am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/3 "2022-07-22T05:45:51Z")

</div>

That's the first thing I tried (I thought it was necessary before the flatten), but I get `[Error] Unrecognized signal name: "F"` ☹

---

<div class="post-metadata">

### Author: ![InesCM](https://avatars.discourse-cdn.com/v4/letter/i/9d8465/32.png) [@InesCM](https://discuss.elastic.co/u/InesCM)
#### Post date: [July 22, 2022, 5:48am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/4 "2022-07-22T05:48:17Z")

</div>

That's the first thing I tried (I thought it was necessary before the flatten), but I get `[Error] Unrecognized signal name: "F"` ☹

 ![error_calculate](https://us1.discourse-cdn.com/elastic/original/3X/d/9/d9fcdba9c3ae491f3a1640a2eb3f420d97839455.png)

---

<div class="post-metadata">

### Author: ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)
#### Post date: [July 22, 2022, 11:17am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/5 "2022-07-22T11:17:35Z")

</div>

Hmm.. That's a bad news. I also tried transforms with various orders without any success.  
It seems like a bug inherent in vega-lite, so how about asking [here](https://github.com/vega/vega-lite/issues)?

---

<div class="post-metadata">

### Author: ![InesCM](https://avatars.discourse-cdn.com/v4/letter/i/9d8465/32.png) [@InesCM](https://discuss.elastic.co/u/InesCM)
#### Post date: [July 26, 2022, 6:01am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/6 "2022-07-26T06:01:03Z")

</div>

Thanks so much for the heads-up, will do that!

---

<div class="post-metadata">

### Author: ![InesCM](https://avatars.discourse-cdn.com/v4/letter/i/9d8465/32.png) [@InesCM](https://discuss.elastic.co/u/InesCM)
#### Post date: [July 26, 2022, 8:44am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/7 "2022-07-26T08:44:00Z")

</div>

Hi,

Managed to make this work after checking in GitHub.  
The key is to calculate the fields in the transform section:

```
"transform": [
{"calculate": "datum.frequencies.freqs.buckets", "as": "F"},
{"flatten": ["F"]},
{"flatten": ["F.rangos.buckets"], "as": ["b"]},
{"calculate": "datum.b.key", "as": "key"},
{"calculate": "datum.b.doc_count", "as": "count"}

```

],

---

<div class="post-metadata">

### Author: ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)
#### Post date: [July 27, 2022, 9:27am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/8 "2022-07-27T09:27:46Z")

</div>

Thank you for sharing the solution!

---

<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: [August 24, 2022, 9:28am UTC](https://discuss.elastic.co/t/accessing-a-flattened-field-in-kibana-vegalite/310253/9 "2022-08-24T09:28:20Z")

</div>

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