Splunk Search

How to get the combinations of a set of values?

teresachila
Path Finder

Given a set of values (e.g. A,B,C) in a multi-value field, I want to get all the combinations that can be generated by this set, i.e.  A-B, A-C, B-C. This is like using itertools combinations in python, but instead of creating a python custom command, I want to do it natively in splunk.

 

0 Karma
1 Solution

teresachila
Path Finder
| makeresults 
| eval set="A,B,C,D,E|F,G,H"
| eval set=split(set,"|") | mvexpand set
| eval set=split(set,",")
| streamstats count as rownum | eval cluster_label="cluster"+rownum
| eval indikey = set, num_set=mvcount(set)
| mvexpand indikey
| streamstats count as step by cluster_label
| eval key2 = mvindex(set, step, num_set)
| eval combo = mvzip(set, key2, ":::")
| stats values(set) as set values(combo) as combo by cluster_label | eval num_combo=mvcount(combo)

I used ":::" as the delimiter but it can be anything.  This generates the field "combo" which contains the combinations in a multivalue field.

View solution in original post

0 Karma

teresachila
Path Finder
| makeresults 
| eval set="A,B,C,D,E|F,G,H"
| eval set=split(set,"|") | mvexpand set
| eval set=split(set,",")
| streamstats count as rownum | eval cluster_label="cluster"+rownum
| eval indikey = set, num_set=mvcount(set)
| mvexpand indikey
| streamstats count as step by cluster_label
| eval key2 = mvindex(set, step, num_set)
| eval combo = mvzip(set, key2, ":::")
| stats values(set) as set values(combo) as combo by cluster_label | eval num_combo=mvcount(combo)

I used ":::" as the delimiter but it can be anything.  This generates the field "combo" which contains the combinations in a multivalue field.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...