Search code examples
elasticsearchkibanavegavega-lite

Tranform data in Vega


I'm using vega in kibana for visualizing data. My data like this (elastic search aggregation )

{
          "key_as_string" : "2020-01-10",
          "key" : 1578614400000,
          "doc_count" : 1198,
          "look_up" : {
            "doc_count" : 977,
            "unlock_not_suggested" : {
              "doc_count" : 502
            }
          }
        },
        {
          "key_as_string" : "2020-01-11",
          "key" : 1578700800000,
          "doc_count" : 924,
          "look_up" : {
            "doc_count" : 712,
            "unlock_not_suggested" : {
              "doc_count" : 392
            }
          }
        },

but I want to flatten like this to visualizing the funnel chart. So how can i do this. I have searched transform in vega but I don't know how to do this. Thank you for your help

{
          "key_as_string" : "2020-01-10",
          "key" : 1578614400000,
          "doc_count" : 1198,
          "look_up" : "977"
          "unlock_not_suggested": "502"
        },

Solution

  • With Vega spec directly, I'd use the "project" transform like this:

    "transform": [
      {
        "type": "project",
        "fields": [
          "key_as_string",
          "key",
          "doc_count",
          "look_up.doc_count",
          "look_up.unlock_not_suggested.doc_count"
        ],
        "as": [
          "key_as_string",
          "key",
          "doc_count",
          "look_up",
          "unlock_not_suggested"
        ]
      }
    ]