# Vega - Multi-level Sankey in Kibana

**URL:** <https://discuss.elastic.co/t/vega-multi-level-sankey-in-kibana/269145>\
**Category:** Kibana\
**Created:** [April 3, 2021, 8:50am UTC](https://discuss.elastic.co/t/vega-multi-level-sankey-in-kibana/269145 "2021-04-03T08:50:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpu](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@cpu](https://discuss.elastic.co/u/cpu)\
**Post date:** [April 3, 2021, 8:50am UTC](https://discuss.elastic.co/t/vega-multi-level-sankey-in-kibana/269145/1 "2021-04-03T08:50:07Z")

</div>

Hi All,

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

> [@Multi-level Sankey in Kibana](https://discuss.elastic.co/t/multi-level-sankey-in-kibana/190582):
>
> I was able to successfully make a 2 level sankey graph based on the blog post but wasn't able to find anything to make the graph multi-level. Is there a way to extend the sankey to multiple layered graph? Any help would be greatly appreciated!

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!

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [April 23, 2021, 9:35am UTC](https://discuss.elastic.co/t/vega-multi-level-sankey-in-kibana/269145/2 "2021-04-23T09:35:49Z")

</div>

Hi @cpu ,  
maybe this article could help: [Kibana Vega Visualizations: Sankey | Yuri Astrakhan](https://nyurik.github.io/Vega-Sankey-Graph-for-Kibana/)

---

<div class="post-metadata">

**Author:** ![cpu](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@cpu](https://discuss.elastic.co/u/cpu)\
**Post date:** [April 23, 2021, 10:12am UTC](https://discuss.elastic.co/t/vega-multi-level-sankey-in-kibana/269145/3 "2021-04-23T10:12:30Z")

</div>

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 ☹

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...

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/3/23a50433a73d35346d46f743862a07ba8e47e333.jpeg)  
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:

```auto
        // 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:

```auto
{
  "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:

```auto
{
  "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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 21, 2021, 10:12am UTC](https://discuss.elastic.co/t/vega-multi-level-sankey-in-kibana/269145/4 "2021-05-21T10:12:31Z")

</div>

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