How to access data without knowing the field names in vega?

Hi!
I wanted to know if there is a way to access data from my index (which contains multiple documents and each document contains different type of fields, for eg., one document might contain fields Aa, Ba and Ca whereas another document might contain fields Ba, Da.) without knowing the field names.
I have pasted my code snippet which works for index containing documents which have the same fields(for eg., every document contains fields Aa, Ba, Ca and Da.)

{
  "$schema": "https://vega.github.io/schema/vega/v3.3.json",
  "autosize": {
    "type": "fit",
    "resize": true
  },
  "data": [
    {
      "name": "table",
      "url": {
        "index": "xyz",
        "body": {
          "query": {
            "bool": {
              "must": [
                "%dashboard_context-must_clause%"
              ],
              "filter": [],
              "should": [],
              "must_not": [
                "%dashboard_context-must_not_clause%"
              ]
            }
          }
        },
        "size": 10
      },
      "format": {
        "property": "hits.hits"
      }
    },
// I want to make the underlying part of the code more generic
        {
      "name": "proj",
      "source": "table",
      "transform": [
      {
        "type": "project",
        "fields": ["_source.AdditionalOutput.Aa", "_source.AdditionalOutput.Ba", "_source.AdditionalOutput.Ca", "_source.AdditionalOutput.Da", "_source.AdditionalOutput.Ea"],
        "as": ["Aa", "Ba", "Ca", "Da", "Ea"]
      }]
    }, 
    {
      "name": "trans",
      "source": "proj",
      "transform": [
        {
          "type": "flatten",
          "fields": [ "Aa", "Ba", "Ca", "Da", "Ea"]
        }
      ]
    }

I don't think it's currently possible, @nyuriks maybe you know it otherwise?

As far as I know, there is no way to enumerate all available keys in an object in Vega. You might want to ask the Vega team to add either a function that returns a list of keys of an object, or a transformation that would create a list of datums, one datum per available key.

1 Like

Thank you for your suggestion. I wanted to know how to contact the Vega team to add such function or transform.

See issues in https://github.com/vega/vega

1 Like

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