Splunk Search

How to display timechart for certain time period without being affected by earliest?

ojtoids
Explorer

Im using a search query to search for data in "all time" but want to display timechart only for last 60 days. If i try to use "earliest=-2mon" it shows the timechart for 2 months but also loses the data past 60 days which projects wrong data in timechart.

 

Current query looks like this 

 

 

 

index=data "search criteria" earliest=-2mon | | timechart usenull=f span=1w count by datapoints

 

 

 

 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=data "search criteria"
| timechart usenull=f span=1w count by datapoints
| where _time >= relative_time(now(),"-2mon")

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=data "search criteria"
| timechart usenull=f span=1w count by datapoints
| where _time >= relative_time(now(),"-2mon")

PickleRick
SplunkTrust
SplunkTrust

OK, maybe I fail to see the point here but how is searching across all time and only at the end limiting by _time better than setting earliest? Unless of course there's something strange done with time in the middle, but I assume it isn't. The search in the form of search all time | transform | limit by _time would be hella ineffective since splunk would do a lot of unnecessary calculations which it will in the end drop.

0 Karma

tshah-splunk
Splunk Employee
Splunk Employee

Hey @ojtoids,

You can use the head command to display the top 8 results. However, it would not be much optimistic approach. Also, when you use earliest in the search query itself, it doesn't matter how much time you select in the time range picker. The query will run for the time defined using the earliest command only. So, if you want to search for data using All time and still display the timechart for the last 2 months only, I would suggest using the head command. Your query should look like below:

index=data "search criteria" earliest=-2mon | | timechart usenull=f span=1w count by datapoints
| head 8 ```Top 8 results```

 

---
If you find the answer helpful, an upvote/karma is appreciated
0 Karma

ojtoids
Explorer

Hello @tshah-splunk 

Thank you for providing the above. But its not working as its showing top results only for one trendline. I have eval with 5 conditions before the timechart and it displays results only for the first eval condition. 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

It's hard to help without more details to your search.

All I can say for now is that you're  using timechart count so you're just aggregating your data points by counting regardless of their value so the actual evals probably don't matter much. But it's hard to say anything past that.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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