Dashboards & Visualizations

Graph edge weight SPL query

mohitab
Path Finder

I could not figure out the proper title, so kindly bear with me. The query results in edge lengths of a Graph.

I have output of a query like this:

x y weight

a b 10
b a 15
a c 12
c a 15

I want to get desired output like:

x y weight

a b 25
a c 27

Any ideas?

Tags (2)
0 Karma
1 Solution

aweitzman
Motivator

Try this:

...your search...
| eval edges=x.",".y 
| makemv delim="," edges 
| eval edgessorted=mvjoin(mvsort(edges),",") 
| stats sum(weight) as weight by edgessorted 
| rex field=edgessorted "(?<x>.*),(?<y>.*)" 
| table x y weight

The trick here is to create a new field (edges) that holds both the x and y values, then use multivalue field functions to sort them so that the edges appear in the same order. Once you've done that you can sum the weights, and lastly get the x and y values back out.

View solution in original post

aweitzman
Motivator

Try this:

...your search...
| eval edges=x.",".y 
| makemv delim="," edges 
| eval edgessorted=mvjoin(mvsort(edges),",") 
| stats sum(weight) as weight by edgessorted 
| rex field=edgessorted "(?<x>.*),(?<y>.*)" 
| table x y weight

The trick here is to create a new field (edges) that holds both the x and y values, then use multivalue field functions to sort them so that the edges appear in the same order. Once you've done that you can sum the weights, and lastly get the x and y values back out.

Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...