Splunk Search

The stats command collect data together if the value is the same

sarit_s
Communicator

Hello
im running this query:
((index=ssys_internal_fdm OR index=other_fdm) AND sourcetype!=machine)

source=*
| stats values(*) as * earliest(_time) as first_time latest(_time) as last_time by SerialNumber 
| convert timeformat="%Y-%m-%d %H:%M:%S" ctime(first_time) as first_time ctime(last_time) as last_time
| search SerialNumber=D00520
| table Region  PrinterType SerialNumber first_time last_time

since this SerialNumber exists in two indexes im getting this result:

> Region    PrinterType     SerialNumber    first_time                 last_time
 INTERNAL      Dorado_F370    D00520           2019-03-20 00:15:10      2019-06-17 19:52:05
 OTHER           Stratasys F370

this is a very good result for another report but i need it to be in separate rows
is it possible ?

thanks

Tags (2)
0 Karma
1 Solution

harsmarvania57
Ultra Champion

Hi,

If you want result based on SerialNumber and Index then please try below query

((index=ssys_internal_fdm OR index=other_fdm) AND sourcetype!=machine)
source=*
| stats values(*) as * earliest(_time) as first_time latest(_time) as last_time by SerialNumber, index 
| convert timeformat="%Y-%m-%d %H:%M:%S" ctime(first_time) as first_time ctime(last_time) as last_time
| search SerialNumber=D00520
| table Region  PrinterType SerialNumber first_time last_time

View solution in original post

0 Karma

harsmarvania57
Ultra Champion

Hi,

If you want result based on SerialNumber and Index then please try below query

((index=ssys_internal_fdm OR index=other_fdm) AND sourcetype!=machine)
source=*
| stats values(*) as * earliest(_time) as first_time latest(_time) as last_time by SerialNumber, index 
| convert timeformat="%Y-%m-%d %H:%M:%S" ctime(first_time) as first_time ctime(last_time) as last_time
| search SerialNumber=D00520
| table Region  PrinterType SerialNumber first_time last_time
0 Karma

sarit_s
Communicator

perfect ! thanks

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...