Splunk Search

count number of serialnumber with dc takes lots of time

sarit_s
Communicator

hello
i have this query :
index = amer_pj
| SerialNumber
| Region
| stats dc(SerialNumber) as SerialNumber by Region
| table SerialNumber

which supposed to count the number of uniqe SerialNumbers
for last 30 days it take more than an hour to complete the query
what am i doing wrong ? is there a better way to do it ?
is there a way to save the result of the last run ?
(it is a dashboard, not a report)

thanks

Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

When you say source, you means "source" (generally file name) metadata field? If yes, then try this version: Should be way faster

| tstats count WHERE index = amer_pj  by source
| `SerialNumber`
| `Region`
| stats dc(SerialNumber) as SerialNumber by Region
| table SerialNumber

View solution in original post

0 Karma

somesoni2
Revered Legend

When you say source, you means "source" (generally file name) metadata field? If yes, then try this version: Should be way faster

| tstats count WHERE index = amer_pj  by source
| `SerialNumber`
| `Region`
| stats dc(SerialNumber) as SerialNumber by Region
| table SerialNumber
0 Karma

sarit_s
Communicator

perfect !!!
please edit your answer so i will be able to accept it

0 Karma

MuS
SplunkTrust
SplunkTrust

Please accept this answer if it solved your problem.

cheers, MuS

0 Karma

Vijeta
Influencer

May be doing extraction at index time will help.
Also scheduled summary indexing is a good option for your case.

0 Karma

sarit_s
Communicator

the rex is not the problem since im using it in lots of other queries

how can i use summary ?

0 Karma

Vijeta
Influencer

@sarit_s Write your search and save it as a report .At the end of your search collect the output data in a summary index (say test_summary) using collect command and schedule it to run as per your need may be once a day based on last 30 days date time range. The _time in summary index can be changed as per your need else it will take time at which scheduled search ran.
| collect index=test_summary

Once data is collected in test_summary , you can simply query on index=test_summary in your dashboard or report.

0 Karma

sarit_s
Communicator

thanks !

0 Karma

somesoni2
Revered Legend

What do those two macros do??

0 Karma

sarit_s
Communicator

extract SerialNumber and Region from source

0 Karma

Vijeta
Influencer

How many events you have in 30 day time frame.You can summarize your data in a summary index over last 30 days and use the summary index in your report.

Also try this query

index=amer_pj| fields SerialNumber , Region | stats dc(SerialNumber) as SerialNumber by Region
0 Karma

sarit_s
Communicator

its still very slow..

i have millions of events in 30 days
how can i use summary ?

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...