Splunk Search

How to display specific fields in statistics?

wuming79
Path Finder

References to tutorial http://docs.splunk.com/Documentation/Splunk/6.5.3/SearchTutorial/Searchwithfieldlookups,
sourcetype=access_* status=200 action=purchase [search sourcetype=access_* status=200 action=purchase | top limit=1 clientip | table clientip] | stats count AS "Total Purchased", dc(productId) AS "Total Products", values(productId) AS "Products ID" BY clientip | rename clientip AS "VIP Customer" will display 4 fields, "VIP Customer", "Total Purchases", "Total Products" and "Product ID".

How do I show also the Product Name in this search?

Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

HI wuming79,
where is Product_Name field?

if it's in your index, you can add to your stats command also:

values(Product_Name) AS Product_Name

if instead it's in a lookup, you have to add a row before the stats command:

sourcetype=access_ status=200 action=purchase 
[search sourcetype=access_ status=200 action=purchase | top limit=1 clientip | table clientip] 
| lookup products.csv  productId OUTPUT Product_Name 
| stats stats count AS "Total Purchased", dc(productId) AS "Total Products", values(productId) AS "Products ID" values(Product_Name) AS Product_Name BY clientip | rename clientip AS "VIP Customer".

For performance, I always prefer to insert index in my main search.

Bye.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

HI wuming79,
where is Product_Name field?

if it's in your index, you can add to your stats command also:

values(Product_Name) AS Product_Name

if instead it's in a lookup, you have to add a row before the stats command:

sourcetype=access_ status=200 action=purchase 
[search sourcetype=access_ status=200 action=purchase | top limit=1 clientip | table clientip] 
| lookup products.csv  productId OUTPUT Product_Name 
| stats stats count AS "Total Purchased", dc(productId) AS "Total Products", values(productId) AS "Products ID" values(Product_Name) AS Product_Name BY clientip | rename clientip AS "VIP Customer".

For performance, I always prefer to insert index in my main search.

Bye.
Giuseppe

wuming79
Path Finder

Thanks Cusello!

0 Karma

gcusello
SplunkTrust
SplunkTrust

HI wuming79,
if you're satisfied of this answer, please accept it.
Bye.
Giuseppe

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!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...