<?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: Using Transaction on one to many relationship data in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134106#M36645</link>
    <description>&lt;P&gt;Actually I might have more new and trade messages which wont match up based on "seq" field, I only want to display the NEW and TRADE data which matches based on "seq" field&lt;/P&gt;</description>
    <pubDate>Wed, 09 Jul 2014 14:37:33 GMT</pubDate>
    <dc:creator>shah_nishay</dc:creator>
    <dc:date>2014-07-09T14:37:33Z</dc:date>
    <item>
      <title>Using Transaction on one to many relationship data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134103#M36642</link>
      <description>&lt;P&gt;I have following data from a log file and I am trying to create a Report on Splunk site.&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3555 | status= "TRADE", seq="34521", out_time ="34527"&lt;BR /&gt;
2014-07-08 16:09:55.966473 | orderID | b6ef3555 | status= "TRADE", seq="34522", out_time ="34528"&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3559 | status= "NEW", seq="34522", out_time="34533"&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3560 | status= "NEW", seq="34522", out_time="34535"&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3562 | status= "NEW", seq="34523", out_time="34537"&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3555 | status= "TRADE", seq="34552", out_time ="34540"&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3561 | status= "TRADE", seq="34554", out_time="34559"&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3565 | status= "NEW", seq="34554", out_time="34568"&lt;/P&gt;

&lt;P&gt;2014-07-08 16:09:55.966473 | orderID | b6ef3567 | status= "NEW", seq="34555", out_time="34570"&lt;/P&gt;

&lt;P&gt;I want to calculate the out_time difference for only those status='NEW" message which can be matched with Trade based on seq field&lt;/P&gt;

&lt;P&gt;My output should look like : &lt;/P&gt;

&lt;P&gt;OrderID,out_time_diff,out_time_New,out_time_Trade&lt;/P&gt;

&lt;P&gt;b6ef3559,5,34533,34528&lt;/P&gt;

&lt;P&gt;b6ef3560,7,34535,34528&lt;/P&gt;

&lt;P&gt;b6ef3565,14,34568,4554&lt;/P&gt;

&lt;P&gt;I can match the Trade message to New message based on "seq" field but since I can have one to many relationships between trade to new message, I am unable to calculate the differences  using "transaction seq" command.&lt;BR /&gt;
Also plz note that I might have some extra trade and extra new messages which I do not want to take into consideration.&lt;BR /&gt;
What are the other options apart from using transaction ?&lt;BR /&gt;
Or is there a way I can use transaction so as to reuse the data from one line to multiple other lines ?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:00:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134103#M36642</guid>
      <dc:creator>shah_nishay</dc:creator>
      <dc:date>2020-09-28T17:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using Transaction on one to many relationship data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134104#M36643</link>
      <description>&lt;P&gt;You should be able to use something along these lines:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search | eventstats first(eval(case(status=="TRADE",out_time))) as out_time_trade by seq | search status="NEW" | eval out_time_diff = out_time - out_time_trade | table OrderID out_time_diff out_time out_time_trade
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;eventstats&lt;/CODE&gt; looks for the &lt;CODE&gt;TRADE&lt;/CODE&gt; event for each value of &lt;CODE&gt;seq&lt;/CODE&gt; and copies its &lt;CODE&gt;out_time&lt;/CODE&gt; into the &lt;CODE&gt;NEW&lt;/CODE&gt; events.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 23:23:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134104#M36643</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-08T23:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using Transaction on one to many relationship data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134105#M36644</link>
      <description>&lt;P&gt;NOTE:  Edited search to fix typos and add a where condition.  I didn't have access to a splunk instance to test the search out before when I posted it.  You might need to adjust field names and/or capitalization to match your instance (for example: orderID vs OrderID in the eval statement on line 4 of this search.&lt;/P&gt;

&lt;P&gt;Another approach:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... your base search here ... 
eval Base_Time=if(status=="TRADE",out_time,null()) 
| eval New_Time=if(status=="NEW",out_time,null()) 
| eval New_Time_and_OrderID=mvzip(New_Time,orderID) 
| stats values(New_Time_and_OrderID) as New_Time_and_OrderID values(Base_Time) as Base_Time by seq 
| mvexpand New_Time_and_OrderID 
| rex field=New_Time_and_OrderID "(?&amp;lt;New_Time&amp;gt;[^,]+),(?&amp;lt;OrderID&amp;gt;[^,]+)" 
| eval out_time_diff=New_Time-Base_Time 
| where isnotnull(Base_Time) 
| table OrderID out_time_diff Base_Time New_Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should give you the results you are looking for.  When I run this on the sample data you provided, it gives the following results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;OrderID        out_time_diff     Base_Time      New_Time
b6ef3559                   5         34528         34533
b6ef3560                   7         34528         34535
b6ef3565                   9         34559         34568
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OrderID's "b6ef3559" and "b6ef3560" are both "NEW" records, and both have the same sequence number (34522) corresponding to the sequence number of a single "TRADE" record.  How does this work for you?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 12:07:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134105#M36644</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2014-07-09T12:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using Transaction on one to many relationship data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134106#M36645</link>
      <description>&lt;P&gt;Actually I might have more new and trade messages which wont match up based on "seq" field, I only want to display the NEW and TRADE data which matches based on "seq" field&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 14:37:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134106#M36645</guid>
      <dc:creator>shah_nishay</dc:creator>
      <dc:date>2014-07-09T14:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Transaction on one to many relationship data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134107#M36646</link>
      <description>&lt;P&gt;this doesnt work when I have one "trade" and 2 "new" data &lt;BR /&gt;
Also I might have more new and trade messages which wont match up based on "seq" field, I only want to display the NEW and TRADE data which matches based on "seq" field&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 14:38:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134107#M36646</guid>
      <dc:creator>shah_nishay</dc:creator>
      <dc:date>2014-07-09T14:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using Transaction on one to many relationship data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134108#M36647</link>
      <description>&lt;P&gt;I've updated my original answer to address your comment, fix typos, and fix my regex.  Please try it now and see if it works for you.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 16:10:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134108#M36647</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2014-07-09T16:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Transaction on one to many relationship data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134109#M36648</link>
      <description>&lt;P&gt;You can filter for that like this at the start of the second line:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | search status="NEW" out_time_trade=* | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That way a NEW event will only be considered if there is a matching TRADE event for that seq value.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 16:59:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Transaction-on-one-to-many-relationship-data/m-p/134109#M36648</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-09T16:59:48Z</dc:date>
    </item>
  </channel>
</rss>

