Splunk Search

How to select particular path using `where` ?

JyotiP
Path Finder

I have the followinf query

 sourcetype="server" host=*localqa*
    | stats count by Path 
    | rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
    | streamstats window=2 first(Path) as f_path count as c 
    | eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
    | table Path Module count

The output of the above query is

+-------------------------------------------------------------------------------+
|Path                                   | Module                        |count  |
+-------------------------------------------------------------------------------+
|profile                                | profileTravellroute           |212    |
|statements/trialbalance                | trialbalance                  |14     |
|iteneries/breakout                     | execution                     |1041   |
|                                       | orderDetails                  |117    |
|reporting/trans                        | schemes                       |712    |
|                                       | fixedIncome                   |40     |
|reporting                              | FinalizedReports              |161    |
|                                       | PendingReports                |8      |
|                                       | reportEntries                 |14     |
|                                       | closedReport                  |22     |
|                                       | reportTimes                   |82     |
|                                       | Reportposition                |40     |
|                                       | ReportStates                  |68     |
+-------------------------------------------------------------------------------+

I want to select records only for reporting

+-------------------------------------------------------------------------------+
|Path                                   | Module                        |count  |
+-------------------------------------------------------------------------------+
|reporting/trans                        | schemes                       |712    |
|                                       | fixedIncome                   |40     |
|reporting                              | FinalizedReports              |161    |
|                                       | PendingReports                |8      |
|                                       | reportEntries                 |14     |
|                                       | closedReport                  |22     |
|                                       | reportTimes                   |82     |
|                                       | Reportposition                |40     |
|                                       | ReportStates                  |68     |
+-------------------------------------------------------------------------------+

Tried with

sourcetype="server" host=*localqa*
| stats count by Path 
| rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
| streamstats window=2 first(Path) as f_path count as c 
| eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
| where Like (Path, 'reporting%')
| table Path Module count

But not working only the following section are coming

 +------------------------------------------------------------------------------------------------+
    |Path                                           |Module                                |Count       |
    +------------------------------------------------------------------------------------------------+
    |reporting/trans                        | schemes                            |712    |
                                                         | fixedIncome                      |40     |
Tags (1)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@JyotiP

Can you please try these ?

sourcetype="server" host=*localqa* 
| stats count by Path 
| rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
| streamstats window=2 first(Path) as f_path count as c 
| eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
| table Path Module count

OR

sourcetype="server" host=*localqa* 
| stats count by Path 
| rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
| streamstats window=2 first(Path) as f_path count as c 
| eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
 | where like(Path,"%reporting%")
| table Path Module count

UPDATED Answer:

sourcetype="server" host=*localqa* 
| stats count by Path 
| rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
| streamstats window=2 first(Path) as f_path count as c 
| eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
| streamstats window=2 last(Path) as Lpath | eval Lpath=if(Lpath!="",Lpath,NULL) | filldown Lpath
| where like(Lpath,"%reporting%")
| table Path Module Count

Sample Search:

| makeresults | eval Path="profile", Module="profileTravellroute", Count="212"  | append [
| makeresults | eval Path="statements/trialbalance", Module="trialbalance", Count="12" ] | append [
| makeresults | eval Path="iteneries/breakout", Module="execution", Count="121" ] | append [
| makeresults | eval Path="", Module="orderDetails", Count="129" ] | append [
| makeresults | eval Path="reporting/trans", Module="schemes", Count="127" ] | append [
| makeresults | eval Path="", Module="fixedIncome", Count="122" ] | append [
| makeresults | eval Path="reporting", Module="FinalizedReports", Count="125" ] | append [
| makeresults | eval Path="", Module="reportEntries", Count="122" ] | append [
| makeresults | eval Path="", Module="Reportposition", Count="123" ] | table Path Module Count 
| streamstats window=2 last(Path) as Lpath | eval Lpath=if(Lpath!="",Lpath,NULL) | filldown Lpath
| where like(Lpath,"%reporting%")
| table Path Module Count

Thanks

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@JyotiP

Can you please try these ?

sourcetype="server" host=*localqa* 
| stats count by Path 
| rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
| streamstats window=2 first(Path) as f_path count as c 
| eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
| table Path Module count

OR

sourcetype="server" host=*localqa* 
| stats count by Path 
| rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
| streamstats window=2 first(Path) as f_path count as c 
| eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
 | where like(Path,"%reporting%")
| table Path Module count

UPDATED Answer:

sourcetype="server" host=*localqa* 
| stats count by Path 
| rex field=Path "\/api\/(?<Path>.*)\/(v1|v2|v3)\/(?<Module>.*)" 
| streamstats window=2 first(Path) as f_path count as c 
| eval Path=case(c=1,Path,Path!=f_path,Path,1=1,"") 
| streamstats window=2 last(Path) as Lpath | eval Lpath=if(Lpath!="",Lpath,NULL) | filldown Lpath
| where like(Lpath,"%reporting%")
| table Path Module Count

Sample Search:

| makeresults | eval Path="profile", Module="profileTravellroute", Count="212"  | append [
| makeresults | eval Path="statements/trialbalance", Module="trialbalance", Count="12" ] | append [
| makeresults | eval Path="iteneries/breakout", Module="execution", Count="121" ] | append [
| makeresults | eval Path="", Module="orderDetails", Count="129" ] | append [
| makeresults | eval Path="reporting/trans", Module="schemes", Count="127" ] | append [
| makeresults | eval Path="", Module="fixedIncome", Count="122" ] | append [
| makeresults | eval Path="reporting", Module="FinalizedReports", Count="125" ] | append [
| makeresults | eval Path="", Module="reportEntries", Count="122" ] | append [
| makeresults | eval Path="", Module="Reportposition", Count="123" ] | table Path Module Count 
| streamstats window=2 last(Path) as Lpath | eval Lpath=if(Lpath!="",Lpath,NULL) | filldown Lpath
| where like(Lpath,"%reporting%")
| table Path Module Count

Thanks

JyotiP
Path Finder

@kamlesh_vaghela only one record from each path is retrieving in both the query, I want all the records

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@JyotiP
Please check my UPDATED answer.

0 Karma
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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...