@kamlesh_vaghela was on the right direction, just that the subsearch has to return a valid search string. and his subsearch does not end creating a plain string, which can be used in parent search
try the following:
index=aws sourcetype=aws:guardduty [ | makeresults | eval earliest=strptime("01/15/2019:20:00:00","%m/%d/%Y:%H:%M:%S") | eval latest=relative_time(earliest,"+2d@d") | return earliest latest ]
@scottprigge to answer your question, why your technique doesn't work. It is because in your search query you are creating a result set first and then you add filter using search command. However, this search command will only filter events from the results you are already passing to it and those results do not contain fields index and sourcetype and don't have a timestamp (you removed field _time ), which you are also trying to filter on by adding earliest and latest constraints.
To show you what you are actually doing in your expression, try to modify it by removing all conditions in the search command. Something like this:
| makeresults
| fields - _time
| eval earliest=strptime("01/15/2019:20:00:00","%m/%d/%Y:%H:%M:%S")
| eval latest=relative_time(earliest,"+2d@d")
| eval earliest=strftime(earliest,"%m/%d/%Y:%H:%M:%S"), latest=strftime(latest,"%m/%d/%Y:%H:%M:%S")
| search
If it is still not clear, let's extend your query even more by adding some additional field, e.g. foo , and play with filtering by that field:
| makeresults
| fields - _time
| eval earliest=strptime("01/15/2019:20:00:00","%m/%d/%Y:%H:%M:%S")
| eval latest=relative_time(earliest,"+2d@d")
| eval earliest=strftime(earliest,"%m/%d/%Y:%H:%M:%S"), latest=strftime(latest,"%m/%d/%Y:%H:%M:%S")
| eval foo="bar"
| search foo="ba*"
What confused you is that search command, when it is first in the query pipeline, then it retrieves data from the indexes according to the condition. And
| search index=aws sourcetype=aws:guardduty
is the same as just
index=aws sourcetype=aws:guardduty
But when it is anywhere else in the pipeline, then it filters events arriving to it from previous command.
... View more