Vega tree graph in Kibana: how to reference the fields from different indices?

Hi
I am following this example and I am having an issue linking the fields of the indices.
I have two indices one for nodes, and one for the links between them. My indices as follows:
nodes:

     {
        "_index" : "nodes",
        "_type" : "doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "actor0",
          "score" : 0.87,
          "group" : 1,
          "index" : 22
        }
      },
      {
        "_index" : "nodes",
        "_type" : "doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "actor1",
          "score" : 0.6,
          "group" : 1,
          "index" : 65
        }
      },

links:

     {
        "_index" : "links",
        "_type" : "doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "source" : 27,
          "target" : 22,
          "value" : 1.0
        }
  {
....

  "data": [
    {
      "name": "node-data",
      "url": {
        "%context%": true,
      "index": "nodes"

      },
    "format": { "property": "hits.hits" },
    } 
    
    
    {
      "name": "link-data",
      "url": {
        "%context%": true,
      "index": "links"
      
      },
    "format": { "property": "hits.hits" },
    } 

  ],

  "scales": [
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "node-data", "field": "group"},
      "range": {"scheme": "category20c"}
    }
  ],

"marks": [
    {
      "name": "nodes",
      "type": "group",
      "zindex": 1,

      "from": {"data": "node-data"},
      "on": [
        {
          "trigger": "fix",
          "modify": "node",
          "values": "fix === true ? {fx: node.x, fy: node.y} : {fx: fix[0], fy: fix[1]}"
        },
        {
          "trigger": "!fix",
          "modify": "node", "values": "{fx: null, fy: null}"
        }
      ],

      "marks": [{
        "type": "symbol",
        "encode": {
          "update": {
            "fill": {"scale": "color", "field": {"parent": "group"}},
            "stroke": {"value": "white"},
            "size": {"signal": "2 * nodeRadius * nodeRadius"},
            "cursor": {"value": "pointer"}
          }
        }
      }, {
        "type": "text",
        "interactive": false,
        "encode": {
          "enter": {
            "fill": {
              "value": "black"
            },
            "fontSize": {
              "value": 12
            },
            "align": {
              "value": "center"
            },
            "text": {
              "field": {"parent": "name"}
            },
            "y": {
              "value": -5
            }
          }
        }
      }], 

      "transform": [
        {
          "type": "force",
          "iterations": 300,
          "restart": {"signal": "restart"},
          "static": {"signal": "static"},
          "signal": "force",
          "forces": [
            {"force": "center", "x": {"signal": "cx"}, "y": {"signal": "cy"}},
            {"force": "collide", "radius": {"signal": "nodeRadius"}},
            {"force": "nbody", "strength": {"signal": "nodeCharge"}},
            {"force": "link", "links": "link-data", "distance": {"signal": "linkDistance"}}
          ]
        }
      ]
    },
    {
      "type": "path",
      "from": {"data": "link-data"},
      "interactive": false,
      "encode": {
        "update": {
          "stroke": {"value": "#ccc"},
          "strokeWidth": {"value": 0.5}
        }
      },
      "transform": [
        {
          "type": "linkpath",
          "require": {"signal": "force"},
          "shape": "line",
          "sourceX": "datum.source.x", "sourceY": "datum.source.y",
          "targetX": "datum.target.x", "targetY": "datum.target.y"
        }
      ]
    }
  ]
}

I am able to load the two indices but I do not know how to reference them, I am using

to get the data, I also tried to filter the data by using _source : ["field","field"] but that did not work, and I am having missing: undefined error

Thanks.

I can't find any examples of Vega with two named data sections that are directly joined, but it seems possible. I think you might be able to store the data as part of a signal, and then use the signal name to calculate something across both data. This is because signal names are bound to the global scope: https://vega.github.io/vega/docs/expressions/

Okay so if I have only one data source (e.g links above) and I want to extract the target field. How can I do that, I tried to declare a body within the data source with _source to filter fields but I am still getting the meta data, and why I try " _source.target" I am not getting the target value

The path you're typing is probably not matching the exact values that Vega has. If you're on the latest 7.10 release, we have a new Vega Inspector which can help you do this: https://www.elastic.co/guide/en/kibana/current/vega-reference.html#asking-for-help-with-a-vega-spec

Otherwise, you can look at the browser console and type VEGA_DEBUG.vega_spec to see what Vega has actually loaded instead of the URL: https://www.elastic.co/guide/en/kibana/current/vega-reference.html#vega-browser-debugging-console

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