A companion function Sankey Widget that produces data compatible with the widget. For more information about Sankey widgets, see Sankey Diagram Widget.

ParameterTypeRequiredDefault ValueDescription
sourcestringrequired   The field containing the source node ID.
targetstringrequired   The field containing the target node ID.
weightaggregateoptional[a] count(as=_count) A function used to calculate the weight the edges. Good candidates are functions like, for example, sum(), count() or max().

[a] Optional parameters use their default value unless explicitly set.

sankey() Syntax Examples

For a webserver log, shows which URLs match HTTP methods:

logscale
#type=accesslog
| sankey(source=method, target=url)

For a webserver log, shows referrers by URL:

logscale
#type=accesslog referrer!="-"
| sankey(source=referrer, target=url)

sankey() Examples

Click + next to an example below to get the full details.

Create Sankey Diagram Calculating Edge Thickness

Create a Sankey diagram calculating the edge thickness using the sankey() function with an aggregator

Query
logscale
sankey(source="src", target="dst", weight=(sum(cnt)))
Introduction

In this example, the sankey() function is used with the weight parameter to show the edge thickness of the fields cnt (count), dst (destination), and src (source) in a Sankey diagram. Edge thickness in a Sankey diagram represents the magnitude or quantity of flow between nodes.

The edge is the connecting line between source and target nodes, and the thickness represents the weightend value of that connection.

Example incoming data might look like this:

cntdstsrc
12applesjohn
1bananasjohn
1applesjoe
1applessarah
1applessarah
1applessarah
Step-by-Step
  1. Starting with the source repository events.

  2. logscale
    sankey(source="src", target="dst", weight=(sum(cnt)))

    Creates a Sankey diagram showing the sources on the left side (john, joe, sarah), and the targets on the right side (apples, bananas), and then provides the edge thickness based on the sum.

    The default weight parameter is count().

  3. Event Result set.

Summary and Results

The query is used to create a Sankey diagram showing the sources on the left side (john, joe, sarah), and the targets on the right side (apples, bananas), and then display the edge thickness using the weight parameter. In this example, the thickest edge is john → apples (12), the medium edge is sarah → apples (3), and the thin edges are joe → apples (1) and john → bananas (1).

The query is useful for rendering results as a two-level Sankey diagram and visualize flow relationships between nodes. It shows proportional relationships between data categories.

Sample output from the incoming example data:

sourcetargetweight
joeapples1
johnapples12
johnbananas1
sarahapples3
Showing Edge Thickness with Sankey()