Vega - Multi-level Sankey in Kibana

Hi All,

Trying to achieve multi-level sankey in kibana, and I found the thread below:

The user @dhruv477 reported his success...
Please @dhruv477 could you share your solution?
Or does anyone has a solution to share with us?

Thanks in advance!

Hi @cpu ,
maybe this article could help: Kibana Vega Visualizations: Sankey | Yuri Astrakhan

Hi @Marta_Bondyra for your answer!
I really appreciated your effort to support me. THANKS!!!

Unfortunately I already followed this article but I wasn't find the solution to add more than 2 levels in sankey graph :frowning:

Using the script in the article with data mapped as float (not as text) the result sankey is not correct: some lines at second node is not at the correct point...


in this example, the line at left at "0" should be at "9" in the right, but it go to "7".
I suppose this occurs when sortField is generated:

        // Create a sortkey, different for stk1 and stk2 stacks.
        // Space separator ensures proper sort order in some corner cases.
        {
          type: formula
          expr: datum.stack == 'stk1' ? datum.stk1+' '+datum.stk2 : datum.stk2+' '+datum.stk1
          as: sortField
        }

But I'm not sure...

My query is:

{
  "size": 0,
  "aggs": {
    "table": {
      "composite": {
        "size": 10000,
        "sources": [
          {
            "stk1": {
              "terms": {
                "field": "1st_nps"
              }
            }
          },
          {
            "stk2": {
              "terms": {
                "field": "2nd_nps_20210409"
              }
            }
          }
        ]
      }
    }
  },
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "match_all": {}
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

and the response:

{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 8,
    "successful": 8,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1503530,
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "table": {
      "after_key": {
        "stk1": 6,
        "stk2": 10
      },
      "buckets": [
        {
          "key": {
            "stk1": 0,
            "stk2": 6
          },
          "doc_count": 71,
          "stk1": 0,
          "stk2": 6,
          "size": 71
        },
        {
          "key": {
            "stk1": 0,
            "stk2": 7
          },
          "doc_count": 65,
          "stk1": 0,
          "stk2": 7,
          "size": 65
        },
        {
          "key": {
            "stk1": 0,
            "stk2": 8
          },
          "doc_count": 66,
          "stk1": 0,
          "stk2": 8,
          "size": 66
        },
        {
          "key": {
            "stk1": 0,
            "stk2": 9
          },
          "doc_count": 69,
          "stk1": 0,
          "stk2": 9,
          "size": 69
        },
        {
          "key": {
            "stk1": 0,
            "stk2": 10
          },
          "doc_count": 78,
          "stk1": 0,
          "stk2": 10,
          "size": 78
        },
        {
          "key": {
            "stk1": 1,
            "stk2": 6
          },
          "doc_count": 78,
          "stk1": 1,
          "stk2": 6,
          "size": 78
        },
        {
          "key": {
            "stk1": 1,
            "stk2": 7
          },
          "doc_count": 68,
          "stk1": 1,
          "stk2": 7,
          "size": 68
        },
        {
          "key": {
            "stk1": 1,
            "stk2": 8
          },
          "doc_count": 72,
          "stk1": 1,
          "stk2": 8,
          "size": 72
        },
        {
          "key": {
            "stk1": 1,
            "stk2": 9
          },
          "doc_count": 75,
          "stk1": 1,
          "stk2": 9,
          "size": 75
        },
        {
          "key": {
            "stk1": 1,
            "stk2": 10
          },
          "doc_count": 68,
          "stk1": 1,
          "stk2": 10,
          "size": 68
        },
        {
          "key": {
            "stk1": 2,
            "stk2": 6
          },
          "doc_count": 71,
          "stk1": 2,
          "stk2": 6,
          "size": 71
        },
        {
          "key": {
            "stk1": 2,
            "stk2": 7
          },
          "doc_count": 68,
          "stk1": 2,
          "stk2": 7,
          "size": 68
        },
        {
          "key": {
            "stk1": 2,
            "stk2": 8
          },
          "doc_count": 74,
          "stk1": 2,
          "stk2": 8,
          "size": 74
        },
        {
          "key": {
            "stk1": 2,
            "stk2": 9
          },
          "doc_count": 79,
          "stk1": 2,
          "stk2": 9,
          "size": 79
        },
        {
          "key": {
            "stk1": 2,
            "stk2": 10
          },
          "doc_count": 90,
          "stk1": 2,
          "stk2": 10,
          "size": 90
        },
        {
          "key": {
            "stk1": 3,
            "stk2": 6
          },
          "doc_count": 64,
          "stk1": 3,
          "stk2": 6,
          "size": 64
        },
        {
          "key": {
            "stk1": 3,
            "stk2": 7
          },
          "doc_count": 74,
          "stk1": 3,
          "stk2": 7,
          "size": 74
        },
        {
          "key": {
            "stk1": 3,
            "stk2": 8
          },
          "doc_count": 79,
          "stk1": 3,
          "stk2": 8,
          "size": 79
        },
        {
          "key": {
            "stk1": 3,
            "stk2": 9
          },
          "doc_count": 77,
          "stk1": 3,
          "stk2": 9,
          "size": 77
        },
        {
          "key": {
            "stk1": 3,
            "stk2": 10
          },
          "doc_count": 55,
          "stk1": 3,
          "stk2": 10,
          "size": 55
        },
        {
          "key": {
            "stk1": 4,
            "stk2": 6
          },
          "doc_count": 55,
          "stk1": 4,
          "stk2": 6,
          "size": 55
        },
        {
          "key": {
            "stk1": 4,
            "stk2": 7
          },
          "doc_count": 94,
          "stk1": 4,
          "stk2": 7,
          "size": 94
        },
        {
          "key": {
            "stk1": 4,
            "stk2": 8
          },
          "doc_count": 71,
          "stk1": 4,
          "stk2": 8,
          "size": 71
        },
        {
          "key": {
            "stk1": 4,
            "stk2": 9
          },
          "doc_count": 70,
          "stk1": 4,
          "stk2": 9,
          "size": 70
        },
        {
          "key": {
            "stk1": 4,
            "stk2": 10
          },
          "doc_count": 79,
          "stk1": 4,
          "stk2": 10,
          "size": 79
        },
        {
          "key": {
            "stk1": 5,
            "stk2": 6
          },
          "doc_count": 94,
          "stk1": 5,
          "stk2": 6,
          "size": 94
        },
        {
          "key": {
            "stk1": 5,
            "stk2": 7
          },
          "doc_count": 75,
          "stk1": 5,
          "stk2": 7,
          "size": 75
        },
        {
          "key": {
            "stk1": 5,
            "stk2": 8
          },
          "doc_count": 85,
          "stk1": 5,
          "stk2": 8,
          "size": 85
        },
        {
          "key": {
            "stk1": 5,
            "stk2": 9
          },
          "doc_count": 80,
          "stk1": 5,
          "stk2": 9,
          "size": 80
        },
        {
          "key": {
            "stk1": 5,
            "stk2": 10
          },
          "doc_count": 87,
          "stk1": 5,
          "stk2": 10,
          "size": 87
        },
        {
          "key": {
            "stk1": 6,
            "stk2": 6
          },
          "doc_count": 82,
          "stk1": 6,
          "stk2": 6,
          "size": 82
        },
        {
          "key": {
            "stk1": 6,
            "stk2": 7
          },
          "doc_count": 91,
          "stk1": 6,
          "stk2": 7,
          "size": 91
        },
        {
          "key": {
            "stk1": 6,
            "stk2": 8
          },
          "doc_count": 63,
          "stk1": 6,
          "stk2": 8,
          "size": 63
        },
        {
          "key": {
            "stk1": 6,
            "stk2": 9
          },
          "doc_count": 71,
          "stk1": 6,
          "stk2": 9,
          "size": 71
        },
        {
          "key": {
            "stk1": 6,
            "stk2": 10
          },
          "doc_count": 84,
          "stk1": 6,
          "stk2": 10,
          "size": 84
        }
      ]
    }
  }
}

Does anyone more expert than me could help me to find the solution for this 2 levels sankey and for the >2 levels sankeys too in order to share it with all the community?

Thanks in advance for any help!

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