Splunk Search

Simplifing a search

cpeteman
Contributor

Two Splunk users have saved basically the same search:

searchterms | stats count by punct | table punct,count | append [ search searchterms | dedup punct | table punct,_raw ] | selfjoin punct | sort-count

and

searchterms | stats count by punct | rename punct as spunct | rename count as scount | table spunct scount | append [ search searchterms | dedup punct | rename punct as spunct | table spunct _raw ] | selfjoin spunct

It seems that I should be able to replace both of these with a much simpler search (with no subsearch) such as:

searchterms | stats count by punct | dedup punct | table punct,count,_raw | sort-count

The goal being to give one _raw message for each punct type along with the punct message and the number of occurrences of that punct. However the _raw field is empty. Help.

SOLUTION: I took a look at this again after having worked a lot more with Splunk and saw there's a way better way to do this:

searchterms | stats count first(_raw) AS raw by punct | sort-count

is all it takes.

Tags (3)
1 Solution

passing
Explorer

Try:

searchterms | stats count first(_raw) AS raw by punct | dedup punct | table punct,count,raw | sort-count

View solution in original post

passing
Explorer

Try:

searchterms | stats count first(_raw) AS raw by punct | dedup punct | table punct,count,raw | sort-count

cpeteman
Contributor

You guys never fail to prove that subsearches are avoidable Thanks!

0 Karma

sowings
Splunk Employee
Splunk Employee

The stats command nuked the _raw because you didn't tell it to include it, whether as a calculated value (values, first, last, avg, max, etc) or as a differentiator in the "by" clause.

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

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 ...