Splunk Search

Search earliest and latest within a field

mrdeterville
Explorer

Hi All;

I have list of events, which includes a field called reported_date, format is yyyy-mm-dd.

I'm trying to create a search that looks for reported_date within the last 15 months of current day. 

Is it possible to do an earliest and latest search within a specific field?

Note: _time does not align with the reported_date.

Any assistance would be greatly appreciated!

TIA

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Short answer is no. Events are timestamped by the _time field and earliest and latest applies to this field, not to some other field in the event. You would have to apply a time period (earliest and latest) to your search to cover enough of your events to find events where reported_date is between the times you are interested in.

View solution in original post

yuanliu
SplunkTrust
SplunkTrust

In addition to what @ITWhisperer says, what is the physical significance of _time currently in your data?  Is there any reason why your ingestion should NOT use reported_date instead of whatever is used in current data?  That will make your requirement so much simpler to fulfill. (If this is a viable alternative, there could be other benefit, too.)

This said, Splunk can always search records where reported_date falls within the last 15 months.  Here, I will illustrate with the following caveat: reported_date is always earlier than or equal to _time.  There can be other strategies to search if this condition is not true but unless that is a problem in your case, the following method is simpler.

<your search criteria> earliest=-15mon
| where relative_time(now(), "-15mon") < strptime(reported_date, "%F")
``` "%F" -> "%Y-%m-%d" ```

 

Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Short answer is no. Events are timestamped by the _time field and earliest and latest applies to this field, not to some other field in the event. You would have to apply a time period (earliest and latest) to your search to cover enough of your events to find events where reported_date is between the times you are interested in.

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: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

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

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