Splunk Enterprise

Recombining events after mvexpand

DATT
Explorer

Hello everybody,

I'm working on a query that does the following:

1. Pull records, mvexpand on a field named INTEL. This is a multi-value field that could have anywhere from 1 to 11 different values.

2. Once expanded, perform a lookup using INTEL to retrieve a field WEIGHT. A weight is assigned to each INTEL value, between 1 and 5.

3. After the lookup, collapse the split records back into one record. 

At first glance I figured I could do `... | mvexpand | lookup | mvcombine | nomv` but since the records are no longer identical because both INTEL and WEIGHT are different, I don't think I can use mvcombine anymore.

To Visually demonstrate the issue

IDINTEL
12345A, B, C, D

 

After mvexpand

IDINTEL
12345A
12345B
12345C
12345D

 

After Lookup

IDINTELWEIGHT
123456A1
123456B2
123456C3
123456D4

 

Ultimately, I would like to get back to this

IDINTELWEIGHT
123456A,B,C,D1,2,3,4

 

Any tips?

Labels (1)
Tags (1)
0 Karma
1 Solution

renjith_nair
Legend

@DATT ,
try using stats on those values

| stats delim="," list(INTEL) as INTEL,list(WEIGHT) as WEIGHT 
| nomv INTEL
| nomv WEIGHT

Here is a run anywhere example . Add/remove your columns according to the requirements

| makeresults | fields - _time 
| eval INTEL="A B C D E" | makemv INTEL | mvexpand INTEL 
| streamstats count | eval WEIGHT=count | rename count as ID 
| makemv delim="," INTEL 
| rename comment as "Above is just data generation" 
| stats delim="," list(INTEL) as INTEL,list(WEIGHT) as WEIGHT 
| nomv INTEL 
| nomv WEIGHT
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

renjith_nair
Legend

@DATT ,
try using stats on those values

| stats delim="," list(INTEL) as INTEL,list(WEIGHT) as WEIGHT 
| nomv INTEL
| nomv WEIGHT

Here is a run anywhere example . Add/remove your columns according to the requirements

| makeresults | fields - _time 
| eval INTEL="A B C D E" | makemv INTEL | mvexpand INTEL 
| streamstats count | eval WEIGHT=count | rename count as ID 
| makemv delim="," INTEL 
| rename comment as "Above is just data generation" 
| stats delim="," list(INTEL) as INTEL,list(WEIGHT) as WEIGHT 
| nomv INTEL 
| nomv WEIGHT
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

DATT
Explorer

This got me close enough to what I needed.  In my effort to streamline and reduce clutter I oversimplified the issue in my original post.  In any case though, thank you for the help!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

@renjith_nair is missing a by clause

| stats delim="," list(INTEL) as INTEL,list(WEIGHT) as WEIGHT by ID
| nomv INTEL
| nomv WEIGHT
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...