Splunk Search

Return on certain field values in my search

Clancy_Moped
Engager

Hi Community,

I'm fairly inexperienced when it comes to anything other than quite basic searches, so my apologies in advance.

I have a field which returns several values, and I only wish to return one in my searches.

The field name is "triggeredComponents{}.triggeredFilters{}.trigger.value" and it returns several values of different types, for example:

1
5
out
text / text text text
hostname1
hostname2
445


I only wish to retrieve and view the "text / text text text" value, and then pop that into a |stats command. Please can someone offer some advise?

Many thanks in advance!

Labels (2)
0 Karma
1 Solution

dtburrows3
Builder

I think an eval expression like this would do it.

 

 

 

 

| eval
        targeted_component=case(
            mvcount('triggeredComponents{}.triggeredFilters{}.trigger.value')==1, if(match('triggeredComponents{}.triggeredFilters{}.trigger.value', "\w+\s*\/\s*\w+(?:\s+\w+)*"), 'triggeredComponents{}.triggeredFilters{}.trigger.value', null()),
            mvcount('triggeredComponents{}.triggeredFilters{}.trigger.value')>1, mvmap('triggeredComponents{}.triggeredFilters{}.trigger.value', if(match('triggeredComponents{}.triggeredFilters{}.trigger.value', "\w+\s*\/\s*\w+(?:\s+\w+)*"), 'triggeredComponents{}.triggeredFilters{}.trigger.value', null()))
            )

 

 

 

 

and the output should look something like this.

dtburrows3_0-1704991086327.png

Using the mvmap function, we loop through each entry of the multivalue field and check if the entry matches a specified regex pattern. If there is a match then we take the value of that entry and insert it into a new field. This new field can potentially also be multivalued, depending on if there are multiple entries from the original field that match the criteria.


and for the stats command part I guess you can just use the newly derived field as a stats by-field to get counts (or whatever kind of stats aggregation is needed)

    | stats
        count as count
            by targeted_component

 

View solution in original post

Clancy_Moped
Engager

Many thanks indeed dtburrows3, this is EXACTLY what I was looking for!

0 Karma

dtburrows3
Builder

I think an eval expression like this would do it.

 

 

 

 

| eval
        targeted_component=case(
            mvcount('triggeredComponents{}.triggeredFilters{}.trigger.value')==1, if(match('triggeredComponents{}.triggeredFilters{}.trigger.value', "\w+\s*\/\s*\w+(?:\s+\w+)*"), 'triggeredComponents{}.triggeredFilters{}.trigger.value', null()),
            mvcount('triggeredComponents{}.triggeredFilters{}.trigger.value')>1, mvmap('triggeredComponents{}.triggeredFilters{}.trigger.value', if(match('triggeredComponents{}.triggeredFilters{}.trigger.value', "\w+\s*\/\s*\w+(?:\s+\w+)*"), 'triggeredComponents{}.triggeredFilters{}.trigger.value', null()))
            )

 

 

 

 

and the output should look something like this.

dtburrows3_0-1704991086327.png

Using the mvmap function, we loop through each entry of the multivalue field and check if the entry matches a specified regex pattern. If there is a match then we take the value of that entry and insert it into a new field. This new field can potentially also be multivalued, depending on if there are multiple entries from the original field that match the criteria.


and for the stats command part I guess you can just use the newly derived field as a stats by-field to get counts (or whatever kind of stats aggregation is needed)

    | stats
        count as count
            by targeted_component

 

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...