Accessing a flattened field in Kibana-VegaLite

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:

  "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:

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:

{
  "$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"}}
}

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

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

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

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?

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

1 Like

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"}

],

1 Like

Thank you for sharing the solution!