TreeMap Vega trouble to get data of index-pattern

Hi, i have some problems to extract data from index-pattern in order to create a treemap in vega visualization.

I have the next data in the index:

{
"_index" : "aml360-vega",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
  "id" : 1,
  "name" : "Total clients"
}
},
{
"_index" : "aml360-vega",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
  "id" : 2,
  "name" : "Total alerts"
}
},
{
"_index" : "aml360-vega",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
  "id" : 3,
  "name" : "Total clients",
  "parent" : 1,
  "size" : 3
}
},
{
"_index" : "aml360-vega",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.0,
"_source" : {
  "id" : 4,
  "name" : "Total clients",
  "parent" : 1,
  "size" : 4
}
},
{
"_index" : "aml360-vega",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
  "id" : 5,
  "name" : "Total alerts",
  "parent" : 2,
  "size" : 5
}
}

And the next vega code:

{
  $schema: https://vega.github.io/schema/vega/v4.json
  width: 960
  height: 500
  padding: 2.5
  autosize: none
  signals: [
    {
      name: layout
      value: squarify
      bind: {
        input: select
        options: ["squarify", "binary", "slicedice"]
      }
    }
    {
      name: aspectRatio
      value: 1.6
      bind: {input: "range", min: 1, max: 5, step: 0.1}
    }
  ]
  data: [
    {
      name: tree
      url: {index: "aml360-vega*", %context%: true}
      transform: [
        {type: "stratify", key: "id", parentKey: "parent"}
        {
          type: treemap
          field: size
          sort: {field: "value"}
          round: true
          method: {signal: "layout"}
          ratio: {signal: "aspectRatio"}
          size: [
            {signal: "width"}
            {signal: "height"}
          ]
        }
      ]
    }
    {
      name: nodes
      source: tree
      transform: [
        {type: "filter", expr: "datum.children"}
      ]
    }
    {
      name: leaves
      source: tree
      transform: [
        {type: "filter", expr: "!datum.children"}
      ]
    }
  ]
  scales: [
    {
      name: color
      type: ordinal
      domain: {data: "nodes", field: "name"}
      range: [
        "#3182bd"
        "#6baed6"
        "#9ecae1"
        "#c6dbef"
        "#e6550d"
        "#fd8d3c"
        "#fdae6b"
        "#fdd0a2"
        "#31a354"
        "#74c476"
        "#a1d99b"
        "#c7e9c0"
        "#756bb1"
        "#9e9ac8"
        "#bcbddc"
        "#dadaeb"
        "#636363"
        "#969696"
        "#bdbdbd"
        "#d9d9d9"
      ]
    }
    {
      name: size
      type: ordinal
      domain: [0, 1, 2, 3]
      range: [256, 28, 20, 14]
    }
    {
      name: opacity
      type: ordinal
      domain: [0, 1, 2, 3]
      range: [0.15, 0.5, 0.8, 1]
    }
  ]
  marks: [
    {
      type: rect
      from: {data: "nodes"}
      interactive: false
      encode: {
        enter: {
          fill: {scale: "color", field: "name"}
        }
        update: {
          x: {field: "x0"}
          y: {field: "y0"}
          x2: {field: "x1"}
          y2: {field: "y1"}
        }
      }
    }
    {
      type: rect
      from: {data: "leaves"}
      encode: {
        enter: {
          stroke: {value: "#fff"}
        }
        update: {
          x: {field: "x0"}
          y: {field: "y0"}
          x2: {field: "x1"}
          y2: {field: "y1"}
          fill: {value: "transparent"}
        }
        hover: {
          fill: {value: "red"}
        }
      }
    }
    {
      type: text
      from: {data: "nodes"}
      interactive: false
      encode: {
        enter: {
          font: {value: "Helvetica Neue, Arial"}
          align: {value: "center"}
          baseline: {value: "middle"}
          fill: {value: "#000"}
          text: {field: "name"}
          fontSize: {scale: "size", field: "depth"}
          fillOpacity: {scale: "opacity", field: "depth"}
        }
        update: {
          x: {signal: "0.5 * (datum.x0 + datum.x1)"}
          y: {signal: "0.5 * (datum.y0 + datum.y1)"}
        }
      }
    }
  ]
}

The problem is that the code don't get data from aml360-vega* index-pattern and don't show anything. I get the vega code from:
https://vega.github.io/editor/#/examples/vega/treemap

@nyuriks any leads here?

thanks

Solved, the problem is I don't get the filelds of the index (_source.id). I share the solution:

{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "width": 960,
  "height": 500,
  "padding": 2.5,
  "autosize": "none",
  "signals": [
    {
      "name": "layout", "value": "squarify",
      "bind": {
        "input": "select",
        "options": [
          "squarify",
          "binary",
          "slicedice"
        ]
      }
    },
    {
      "name": "aspectRatio", "value": 1.6,
      "bind": {"input": "range", "min": 1, "max": 5, "step": 0.1}
    }
  ],
  "data": [
    {
      "name": "tree",
      "url": { "index": "aml360-vega*"
        %context%: true
        _source: ["id", "name", "parent", "size"]},
      format: {property: "hits.hits"},
      "transform": [
        {
          "type": "stratify",
          "key": "_source.id",
          "parentKey": "_source.parent"
        },
        {
          "type": "treemap",
          "field": "_source.size",
          "sort": {"field": "value"},
          "round": true,
          "method": {"signal": "layout"},
          "ratio": {"signal": "aspectRatio"},
          "size": [{"signal": "width"}, {"signal": "height"}]
        }
      ]
    },
    {
      "name": "nodes",
      "source": "tree",
      "transform": [{ "type": "filter", "expr": "datum.children" }]
    },
    {
      "name": "leaves",
      "source": "tree",
      "transform": [{ "type": "filter", "expr": "!datum.children" }]
    }
  ],
  "scales": [
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "nodes", "field": "name"},
      "range": [
        "#3182BD", "#6BAED6", "#9ECAE1", "#C6DBEF", "#E6550D",
        "#FD8D3C", "#FDAE6B", "#FDD0A2", "#31A354", "#74C476",
        "#A1D99B", "#C7E9C0", "#756BB1", "#9E9AC8", "#BCBDDC",
        "#DADAEB", "#636363", "#969696", "#BDBDBD", "#D9D9D9"
      ]
    },
    {
      "name": "size",
      "type": "ordinal",
      "domain": [0, 1, 2, 3],
      "range": [256, 28, 20, 14]
    },
    {
      "name": "opacity",
      "type": "ordinal",
      "domain": [0, 1, 2, 3],
      "range": [0.15, 0.5, 0.8, 1.0]
    }
  ],
  "marks": [
    {
      "type": "rect",
      "from": {"data": "nodes"},
      "interactive": false,
      "encode": {
        "enter": {
          "fill": {"scale": "color", "field": "name"}
        },
        "update": {
          "x": {"field": "x0"},
          "y": {"field": "y0"},
          "x2": {"field": "x1"},
          "y2": {"field": "y1"}
        }
      }
    },
    {
      "type": "rect",
      "from": {"data": "leaves"},
      "encode": {
        "enter": {
          "stroke": {"value": "#fff"}
        },
        "update": {
          "x": {"field": "x0"},
          "y": {"field": "y0"},
          "x2": {"field": "x1"},
          "y2": {"field": "y1"},
          "fill": {"value": "transparent"}
        },
        "hover": {
          "fill": {"value": "red"}
        }
      }
    },
    {
      "type": "text",
      "from": {"data": "nodes"},
      "interactive": false,
      "encode": {
        "enter": {
          "font": {"value": "Helvetica Neue, Arial"},
          "align": {"value": "center"},
          "baseline": {"value": "middle"},
          "fill": {"value": "#000"},
          "text": {"field": "name"},
          "fontSize": {"scale": "size", "field": "depth"},
          "fillOpacity": {"scale": "opacity", "field": "depth"}
        },
        "update": {
          "x": {"signal": "0.5 * (datum.x0 + datum.x1)"},
          "y": {"signal": "0.5 * (datum.y0 + datum.y1)"}
        }
      }
    }
  ]
}

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