Splunk Search

eliminate some value in fields in stats count.

sandeepmakkena
Contributor
index=* 
| spath msg.uri 
| rename msg.uri as url
| rex field=url "shop(?<ex_url>[a-zA-Z\/\-0-9\.]+)" 
| rex field=ex_url "buy-(?<family>[^\/]+)\/(?<product>[^\/]+)" 
| eval url_N="/shop/"+"buy-"+family +"/" + product +"/"
| eval N_url = coalesce(url, url_N)
| stats count by N_url
| sort -count
| head 100

I am trying to find count by URL, but I also need to combine count value that looks like /shop/buy-phone/LG'. /shop/buy-laptop/Mac as /shop/buy-phone/ or /shop/buy-laptop/. Finally, when I count my URL I need to include these group URLs count with the other URL. I tried above, I am missing something.
Thanks for your time.

0 Karma

FrankVl
Ultra Champion

Do I understand correctly that you basically want a count per product (based on the unique url for that product) and a sum per product family? That could be done by doing something like below (including the family in the stats command you already had and then add an eventstats command to calculate the sum of counts by family.

index=* 
| spath msg.uri 
| rename msg.uri as url
| rex field=url "shop(?<ex_url>[a-zA-Z\/\-0-9\.]+)" 
| rex field=ex_url "buy-(?<family>[^\/]+)\/(?<product>[^\/]+)" 
| eval url_N="/shop/"+"buy-"+family +"/" + product +"/"
| eval N_url = coalesce(url, url_N)
| stats count by family,N_url
| eventstats sum(count) as familycount by family
| sort -count
| head 100

If that is not what you're after, please give an example of the expected output you're looking for.

0 Karma

sandeepmakkena
Contributor

Thanks for your response. What I'm looking for is different.
I want a stats count of URL, but I want to group count with this format /shop/buy-family/product/ as one and without that as a single URL.

Here is an example:

url field data:

/fr/shop/buy-phone/LG/v20-%0gsgwwguwfwrwwygswiswosubwbwi-nwsiwuhs/
/Ind/shop/buy-phone/LG/v30-%hxeuteiehiexhi/
/US/shop/buy-phone/Apple/iphone-4s
/ch/shop/buy-phone/LG/v60
/us/shop/buy-laptop/Mac/
/pk/shop/buy-laptop/Mac-pro/
/gr/shop/buy-laptop/Samsung/
/shop/browse/user/
/browse/user/laptop/ 

I want stats to be:

/shop/buy-phone/LG/  -   3
/shop/buy-phone/Apple/ - 1
 /shop/buy-laptop/Mac/ -1
/shop/buy-laptop/Mac-pro/ -1
/shop/buy-laptop/Samsung/ -1
/shop/browse/user/.     -  1
/browse/user/laptop/     - 1
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 ...