Splunk Search

How to derive earliest and latest from the subquery?

msg4sunil
Path Finder

index=app1 [search index=app1 "orderid"| fields id]

How do I modify the above query wherein "search index=app1 "orderid"| fields id" query is run and its first event's time and the last event's time is take as  earliest and latest time respectively for the query, "index=app1"

thus it would look sometime like

index=app1 earliest=x latest=y [search index=app1 "orderid"| fields id]

wherein the values x and y is the first and last event's datetime of the query, "search index=app1 "orderid"| fields id"

Thank you

Labels (2)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Is id required as part of the filtering or just earliest and latest times from the events which match orderid?

index=app1 [
  search index=app1 "orderid"
  | stats latest(_time) as latest earliest(_time) as earliest
  | fields earliest latest
]
0 Karma

PickleRick
SplunkTrust
SplunkTrust

What is the point? Since from what you showed so far you'd be modifying a search with results from the same search which seems a bit pointless.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Should work, i.e. pass the earliest and latest out from the subsearch

index=app1 [
  search index=app1 "orderid"
  | stats latest(_time) as latest earliest(_time) as earliest values(id) 
  | fields id earliest latest
]

 

0 Karma

msg4sunil
Path Finder

@bowesmana , sorry its not working me

The results of both doesnt match since the ID's are different

index=app1 "order1"
| stats count by id


index=app1 [
search index=app1 "order1"
| stats latest(_time) as latest earliest(_time) as earliest values(id)
| fields id earliest latest
]
| stats count by id

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Can you explain what you mean by the ids are different?

What IDs are you referring to and can you provide an example of how the outer and inner searches are supposed to filter each other?

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @msg4sunil,

please try something like this:

index=app1 [ search index=app1 "orderid" | addinfo | rename info_max_time AS latest info_min_time AS earliest | fields id earliest latest ]

Ciao.

Giuseppe

0 Karma

msg4sunil
Path Finder

@gcusello , its pretty close but not exact. 

index=app1 "order1"| stats count by id


index=app1 [ search index=app1 "orderid" | addinfo | rename info_max_time AS latest info_min_time AS earliest | fields id earliest latest ]|stats count by id

Comparing the output of the above command, while most of the ID's matched based on the above but not all.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @msg4sunil,

did you understand which are the not matching IDs?

ciao.

Giuseppe

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...