<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can i get the first event after match a event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-i-get-the-first-event-after-match-a-event/m-p/381439#M167466</link>
    <description>&lt;P&gt;hi @johnny_goya&lt;/P&gt;

&lt;P&gt;Did the answer below solve your problem? If so, please resolve this post by approving it! &lt;BR /&gt;
If your problem is still not solved, keep us updated so that someone else can help ya. Thanks for posting!&lt;/P&gt;</description>
    <pubDate>Thu, 27 Sep 2018 23:04:31 GMT</pubDate>
    <dc:creator>mstjohn_splunk</dc:creator>
    <dc:date>2018-09-27T23:04:31Z</dc:date>
    <item>
      <title>How can i get the first event after match a event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-i-get-the-first-event-after-match-a-event/m-p/381437#M167464</link>
      <description>&lt;P&gt;I want to make a search that match for a event, than get the next event.&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;P&gt;Event1 _time event_hash status_label&lt;BR /&gt;
Event2 _time event_hash status_label&lt;BR /&gt;
Event3 _time event_hash status_label&lt;BR /&gt;
Event4 _time event_hash status_label&lt;/P&gt;

&lt;P&gt;Match:&lt;BR /&gt;
Event2 _time event_hash status_label&lt;BR /&gt;
Event3 _time event_hash status_label&lt;/P&gt;

&lt;P&gt;Match:&lt;BR /&gt;
Event1 _time event_hash status_label&lt;BR /&gt;
Event2 _time event_hash status_label&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:18:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-i-get-the-first-event-after-match-a-event/m-p/381437#M167464</guid>
      <dc:creator>johnny_goya</dc:creator>
      <dc:date>2020-09-29T21:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can i get the first event after match a event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-i-get-the-first-event-after-match-a-event/m-p/381438#M167465</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/88994"&gt;@johnny_goya&lt;/a&gt;&lt;/P&gt;

&lt;P&gt;From given example what I understand is.&lt;/P&gt;

&lt;P&gt;Below is your event&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event1 _time event_hash status_label
Event2 _time event_hash status_label
Event3 _time event_hash status_label
Event4 _time event_hash status_label
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Below is your matching event from any logic&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event2 _time event_hash status_label
Event3 _time event_hash status_label
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;AND &lt;BR /&gt;
Below is your desired output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event1 _time event_hash status_label
Event2 _time event_hash status_label
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Well, if it is then try following search.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;YOUR_SEARCH | eval match=&amp;lt;&amp;lt;YOUR_MATCHING_LOGIC&amp;gt;&amp;gt; | streamstats window=2 earliest(_raw) as prev_event | where match=1&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Note:  I have taken an assumption we have already match field which represents event is matched or not.&lt;BR /&gt;
YOUR_MATCHING_LOGIC should return &lt;CODE&gt;1&lt;/CODE&gt; incase of true and &lt;CODE&gt;0&lt;/CODE&gt;  in case of false.&lt;/P&gt;

&lt;P&gt;My Sample Search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="Event1 _time event_hash status_label
Event2 _time event_hash status_label match=1
Event3 _time event_hash status_label match=1
Event4 _time event_hash status_label" 
| rex max_match=0 field=_raw "(?&amp;lt;T&amp;gt;[^[\n|\.]+)" 
| mvexpand T
| eval _raw=T 
| fields - T | kv | streamstats window=2 earliest(_raw) as prev_event | where match=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:27:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-i-get-the-first-event-after-match-a-event/m-p/381438#M167465</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-09-29T21:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can i get the first event after match a event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-i-get-the-first-event-after-match-a-event/m-p/381439#M167466</link>
      <description>&lt;P&gt;hi @johnny_goya&lt;/P&gt;

&lt;P&gt;Did the answer below solve your problem? If so, please resolve this post by approving it! &lt;BR /&gt;
If your problem is still not solved, keep us updated so that someone else can help ya. Thanks for posting!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 23:04:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-i-get-the-first-event-after-match-a-event/m-p/381439#M167466</guid>
      <dc:creator>mstjohn_splunk</dc:creator>
      <dc:date>2018-09-27T23:04:31Z</dc:date>
    </item>
  </channel>
</rss>

