Splunk Search

Combine dynamic fields into a multivalued field in a search

shivanshu1593
Builder

Hi All,

I'm working on a search, where I currently have the following:

..base search..

| table static_name, static_time, static_title, static_owner,  static_id, static_description

 

Apart from static_title, static_time, static_id, the other fields are dynamic (they change as the search runs with different inputs. static_owner gets replaced by file_name, other fields like fqdn, process, event_hash etc get added to the search)

 

What I'm trying to achieve is that the static values, which always are present in the search, should be shown as separate fields, while dynamic fields are merged into a new, multivalued field called Combined_Field, irrespective of the new fields showing up. They should be merged into them.

| table static_time, static_owner, static_id, Combined_Field (a multivalued field, comprising the values of all the dynamic fields)

 

..base search..

| table static_name, static_time, static_title, static_owner,  static_id, static_description

| eval Combined_Field = null()

| foreach * [ eval Combined_Field=if('<<field>>'==static_time OR '<<field>>'==static_owner OR '<<field>>'==static_id, '<<field>>', mvappend('<<field>>', Combined_Field)) ]

| table static_time, static_owner, static_id, Combined_Field

The Combined_Field always remains empty. Could anyone check and let me know as to what am I doing wrong. Or if this can be achieved via a different approach. I've always tried doing the foreach command with case instead of if, no luck.

 

Thank you in advance,

S

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
Labels (1)
Tags (3)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You need to check is Combined_Field is null before trying to mvappend to it.

| foreach * [ eval Combined_Field=if('<<field>>'==static_time OR '<<field>>'==static_owner OR '<<field>>'==static_id, '<<field>>', if(isnull(Combined_Field),'<<field>>',mvappend('<<field>>', Combined_Field))) ]
0 Karma

shivanshu1593
Builder

Hello @ITWhisperer ,

Thank you for the suggestion. I tried your suggestion, but the field Combined_Fields is still blank.

I used | eval Combined_Fields = null() before foreach. It didn't help either.

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try the fields in the other order in the mvappend

| foreach * [ eval Combined_Field=if('<<field>>'==static_time OR '<<field>>'==static_owner OR '<<field>>'==static_id, '<<field>>', if(isnull(Combined_Field),'<<field>>',mvappend(Combined_Field,'<<field>>'))) ]
0 Karma

shivanshu1593
Builder

It's still blank. Fields didn't get append to the field Combined_Fields. All are showing up as separate fields in the table command and Combined_Fields is empty.

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Did you put the field names in double quotes - also, you should check if <<field>> is Combined_Field so it doesn't get duplicated.

| foreach * [ eval Combined_Field=if('<<field>>'=="static_time" OR '<<field>>'=="static_owner" OR '<<field>>'=="static_id" OR '<<field>>'=="Combined_Field", '<<field>>', if(isnull(Combined_Field),'<<field>>',mvappend(Combined_Field,'<<field>>'))) ]
0 Karma

shivanshu1593
Builder

I did try running the search with field names under double quotes, it still remained blank. 

Regarding <<field>> not being Combined_Fields, not really sure how to check that. Could you please point me to a direction, using which I can take a look.

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I had included it already - thinking about it, perhaps you need the <<field>> in double quotes too when checking for the names.

| foreach * [ eval Combined_Field=if("<<field>>"=="static_time" OR "<<field>>"=="static_owner" OR "<<field>>"=="static_id" OR "<<field>>"=="Combined_Field", '<<field>>', if(isnull(Combined_Field),'<<field>>',mvappend(Combined_Field,'<<field>>'))) ]
0 Karma

shivanshu1593
Builder

I tried with "<<field>>"  as well. Still no results. It's a puzzler. Not really sure what's not working here.

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try with <<FIELD>>

0 Karma

shivanshu1593
Builder

Tried that too. On passing <<field>> without any quotes around it, the if statement fails.

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I meant use FIELD in caps not lowercase

0 Karma

shivanshu1593
Builder

My bad. I tried with <<FIELD>> and it has appended all the values, including static_time, static_owner, static_id, which we tried to filter out in the if block. 

 

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

So you need caps and double quotes

| foreach * [ eval Combined_Field=if("<<FIELD>>"=="static_time" OR "<<FIELD>>"=="static_owner" OR "<<FIELD>>"=="static_id" OR "<<FIELD>>"=="Combined_Field", '<<FIELD>>', if(isnull(Combined_Field),'<<FIELD>>',mvappend(Combined_Field,'<<FIELD>>'))) ]
0 Karma

shivanshu1593
Builder

I've tried to implement that, but its messing up with the fields. There are 17 fields in total in the current iteration, 14 should be in the multivalued field and 3 outside. However, using double quotes and captial fields is reducing the number of fields in the multivalued field down to 8.

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

So the process works? Now, it is down to the actual field names. Which field names work, and which ones don't?

0 Karma

shivanshu1593
Builder

Hello,

None of the fields are working. All of them are present in the multivalued field, Combined_Fields. On covering them and <<FIELD>> in double quotes, they still land up in the multivalued field.

When I put "<<FIELD>>"  == "Combined_Field", then out of 17 fields of this iteration, at least 4 disappear from the multivalued field, leaving only 10 in there instead of 14.

Thank you,
Shiv
###If you found the answer helpful, kindly consider upvoting/accepting it as the answer as it helps other Splunkers find the solutions to similar issues###
0 Karma
Get Updates on the Splunk Community!

Splunk Observability Synthetic Monitoring - Resolved Incident on Detector Alerts

We’ve discovered a bug that affected the auto-clear of Synthetic Detectors in the Splunk Synthetic Monitoring ...

Video | Tom’s Smartness Journey Continues

Remember Splunk Community member Tom Kopchak? If you caught the first episode of our Smartness interview ...

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud?

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud? Learn how unique features like ...