How to access nested json in vega

I am using vega in kibana. I try to access nested json field but I cannot able to access that field, could anyone help me to resolve this issue. I attach my vega json and index name is pie

index data sample:

{ "_index": "pie", "_type": "flare", "_id": "2", "_version": 1, "_score": 1, "_source": { "id": 2, "parent": 1, "data" :{ "memory": 50 } } }

{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"data": [
{
"name": "table",
"url": {

"%context%": "true",

 "index": "pie*",

 "body": {

  "size": "10"


 }
 },

"format": { "property": "hits.hits" },

"transform": [
 {
  "type": "formula",
  "expr": "toNumber(datum[\"_source\"][\"data\"][\"memory\"])",
  "as": "memory"
    }
      ],
 "transform": [{"type": "pie", "field": "memory"}]
 }  ],

  "scales": [
   {
 "name": "r",
  "type": "sqrt",
  "domain": {"data": "table", "field": "memory"},
 "zero": true,
 "range": [20, 100]
     }
   ],

 "marks": [
{
 "type": "arc",
  "from": {"data": "table"},
  "encode": {
   "enter": {
    "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "startAngle": {"field": "startAngle"},
  "endAngle": {"field": "endAngle"},
  "innerRadius": {"value": 20},
  "outerRadius": {"scale": "r", "field": "memory"},
  "stroke": {"value": "#fff"}
},
"update": {
  "fill": {"value": "#ccc"}
},
"hover": {
  "fill": {"value": "skyblue"}
}
  }
   },

{
 "type": "text",
 "from": {"data": "table"},
"encode": {
"enter": {
  "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "radius": {"scale": "r", "field": "memory", "offset": 8},
  "theta": {"signal": "(datum.startAngle + datum.endAngle)/2"},
  "fill": {"value": "#000"},
  "align": {"value": "center"},
  "baseline": {"value": "middle"},
  "text": {"field": "memory"}
 }
}
}
]     
  }

Sorry for the delay in reply. I was able to get this to work by eliminating the duplicate key in your json (transform appears twice).

{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"data": [
{
"name": "table",
"url": {

"%context%": "true",

 "index": "pie*",

 "body": {
  "size": "10"


 }
 },

"format": { "property": "hits.hits" },

"transform": [
 {
  "type": "formula",
  "expr": "toNumber(datum[\"_source\"][\"data\"][\"memory\"])",
  "as": "memory"
    },
    {"type": "pie", "field": "memory"}]
 }
      ],
  "scales": [
   {
 "name": "r",
  "type": "sqrt",
  "domain": {"data": "table", "field": "memory"},
 "zero": true,
 "range": [20, 100]
     }
   ],

 "marks": [
{
 "type": "arc",
  "from": {"data": "table"},
  "encode": {
   "enter": {
    "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "startAngle": {"field": "startAngle"},
  "endAngle": {"field": "endAngle"},
  "innerRadius": {"value": 20},
  "outerRadius": {"scale": "r", "field": "memory"},
  "stroke": {"value": "#fff"}
},
"update": {
  "fill": {"value": "#ccc"}
},
"hover": {
  "fill": {"value": "skyblue"}
}
  }
   },

{
 "type": "text",
 "from": {"data": "table"},
"encode": {
"enter": {
  "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "radius": {"scale": "r", "field": "memory", "offset": 8},
  "theta": {"signal": "(datum.startAngle + datum.endAngle)/2"},
  "fill": {"value": "#000"},
  "align": {"value": "center"},
  "baseline": {"value": "middle"},
  "text": {"field": "memory"}
 }
}
}
]     
  }

thanks Bill_McConaghy

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