Splunk Search

How can I extract a multi value field?

danielbb
Motivator

We have a field called IP-Group. It can be empty or it would have this format - IP-Group={xxxx} {yyyy} {zzz}.

Can I extract it until the last } and maybe extract each value separately as well?

Tags (1)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval temp="IP-Group={xxxx} {yyyy} {zzz}" 
| rex field=temp max_match=0 "\{(?P<result>[^}]+)"

View solution in original post

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval temp="IP-Group={xxxx} {yyyy} {zzz}" 
| rex field=temp max_match=0 "\{(?P<result>[^}]+)"

danielbb
Motivator

Great - this is slick!!!

0 Karma

codebuilder
Influencer

If you are ingesting structured data like JSON or XML, then you can use set kvmode in props.conf for automatic kv field extraction.
I've not personally used it for JSON, but I do use it for XML and it works like a champ, including multi-value fields.

https://docs.splunk.com/Documentation/Splunk/8.0.0/Knowledge/Automatickey-valuefieldextractionsatsea...

----
An upvote would be appreciated and Accept Solution if it helps!

ololdach
Builder

Hi,
please try this:

|makeresults|eval IP-Group="{ip1} {ip2} {ip3} {ip4}"|makemv delim=" " IP-Group | mvexpand IP-Group | rex field=IP-Group "\{(?<ipvalue>.*)\}

You want to have one event per ip value, because the length of your list is dynamic and there is no other way that comes to my mind to parse a variable number of values from a list.
Hope it helps
Oliver

ololdach
Builder

Sorry, cut & paste error 🙂 forgot to paste the final "

0 Karma

danielbb
Motivator

I get *Unbalanced quotes. * on that.

0 Karma

mayurr98
Super Champion

"\{(?<ipvalue>.*)\}" change
add " at the end

danielbb
Motivator

Great! looks good.

0 Karma

mayurr98
Super Champion

try this:

| makeresults 
| eval xx="IP-Group={xxxx} {yyyy} {zzz}" 
| rex field=xx "IP-Group=\{(?<x>[^\}]+)\}\s+\{(?<y>[^\}]+)\}\s+\{(?<z>[^\}]+)"

danielbb
Motivator

The following does it -

| makeresults 
| eval xx="IP-Group={xxxx} {yyyy} {zzz}" 
| rex field=xx "IP-Group=(?<yy>.+\})"

But can we generate a distinct field for each value?

0 Karma

FrankVl
Ultra Champion

Distinct fields as in, ipgroup1=xxx, ipgroup2=yyy, ipgroup3=zzz?

If the actual number of items in the multivalued field is dynamic, that is going to be pretty difficult to solve elegantly.

If the number of possible entries is somewhat limited (e.g. max 3) you can do it like this:

| rex field=xx "IP-Group=\{(?<ipgroup1>[^}]+)\}(?:\s+\{(?<ipgroup2>[^}]+)\})?(?:\s+\{(?<ipgroup3>[^}]+)\})?"

See: https://regex101.com/r/RSfFlu/1

This approach can be extended as far as you want, by just appending more (?:\s+\{(?<ipgroup...>[^}]+)\})? parts. But that gets a bit ugly if it can also be 100 entries.

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...