<?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 do I append event(s) fields to a separate event based on two timestamps? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397884#M174473</link>
    <description>&lt;P&gt;It looks like there are additional values that must be used to correlate the events?&lt;BR /&gt;
Is the 'id' field shown sufficient to associate Set B with Set A data or field 'vehicle_vin' or a combination of both?&lt;BR /&gt;
The sample data you provided would not correlate any values as the time for Set B data is not within any of Set A event time ranges. The second event, the end_time is before the start_time??? Guess you hand generated this?&lt;BR /&gt;
Are you trying to achieve an association of the lat/long with the start and end times? Is that the goal?&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 22:10:04 GMT</pubDate>
    <dc:creator>laurie_gellatly</dc:creator>
    <dc:date>2020-09-29T22:10:04Z</dc:date>
    <item>
      <title>How do I append event(s) fields to a separate event based on two timestamps?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397881#M174470</link>
      <description>&lt;P&gt;Hello, &lt;/P&gt;

&lt;P&gt;I have two sets of data: Trip Metadata(A) and Individual Trip Coordinates(B). &lt;/P&gt;

&lt;P&gt;Set A fields: &lt;BR /&gt;
- StartTime&lt;BR /&gt;
- EndTime&lt;/P&gt;

&lt;P&gt;Set B fields:&lt;BR /&gt;
- Coordinates (Latitude and Longitude)&lt;BR /&gt;
- Timestamp&lt;/P&gt;

&lt;P&gt;How do I append the Set B Coordinate fields to events of Set A only if the Set B timestamp is between the Set A Start and End time?&lt;/P&gt;

&lt;P&gt;Thanks for reading.&lt;/P&gt;

&lt;P&gt;Both sets of data live in the same index but with different source types. &lt;/P&gt;

&lt;P&gt;Sample Data: &lt;BR /&gt;
Set A Trip Metadata (Multiple events(trips))&lt;BR /&gt;
{   [-] &lt;BR /&gt;
     device_sn:  GXXXXXG&lt;BR /&gt;&lt;BR /&gt;
     id:     qwg098wq7wq8&lt;BR /&gt;&lt;BR /&gt;
     trip_distance_km:   4.927902&lt;BR /&gt;&lt;BR /&gt;
     trip_end_time:  2018-11-19T23:46:56.0000000-05:00&lt;BR /&gt;&lt;BR /&gt;
     trip_start_time:    2018-11-19T23:36:35.0000000-05:00&lt;BR /&gt;&lt;BR /&gt;
     vehicle_name:   Eric Jim&lt;BR /&gt;
     vehicle_vin:    WG15&lt;BR /&gt;
},&lt;BR /&gt;
{   [-] &lt;BR /&gt;
     device_sn:  GXXXXXG&lt;BR /&gt;&lt;BR /&gt;
     id:     23jg9802j32&lt;BR /&gt;
     trip_distance_km:   4.927902&lt;BR /&gt;&lt;BR /&gt;
     trip_end_time:  2018-11-19T23:06:56.0000000-05:00&lt;BR /&gt;&lt;BR /&gt;
     trip_start_time:    2018-11-19T23:16:35.0000000-05:00&lt;BR /&gt;&lt;BR /&gt;
     vehicle_name:   Eric Jim&lt;BR /&gt;&lt;BR /&gt;
     vehicle_vin:    WG15&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;Set B Trip Individual Coordinates&lt;BR /&gt;
{   [-] &lt;BR /&gt;
     device_sn:  GXXXXXG&lt;BR /&gt;&lt;BR /&gt;
     id:     9854gu45g&lt;BR /&gt;
     latitude:   33.7303314 &lt;BR /&gt;
     longitude:  -116.96965 &lt;BR /&gt;
     speed_kph:  0&lt;BR /&gt;&lt;BR /&gt;
     timestamp:  2018-11-19T23:47:02.0000000-05:00&lt;BR /&gt;&lt;BR /&gt;
     vehicle_name:  Eric Jim&lt;BR /&gt;&lt;BR /&gt;
     vehicle_vin:    WG15&lt;BR /&gt;
}&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:05:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397881#M174470</guid>
      <dc:creator>kligms</dc:creator>
      <dc:date>2020-09-29T22:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I append event(s) fields to a separate event based on two timestamps?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397882#M174471</link>
      <description>&lt;P&gt;Could you post some sample data from the index?&lt;BR /&gt;
index=theindex sourcetype=trip_meta OR sourcetype=trip_coords&lt;BR /&gt;
So you're saying that _time for the coords is &amp;gt; starttime and &amp;lt; endtime for the trip_meta event (or events)?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:04:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397882#M174471</guid>
      <dc:creator>laurie_gellatly</dc:creator>
      <dc:date>2020-09-29T22:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I append event(s) fields to a separate event based on two timestamps?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397883#M174472</link>
      <description>&lt;P&gt;I added some sample data. Yes, the coords time has to be between the trip meta start and end time. There are multiple trips and there's alot of trip coordinate events. &lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 13:24:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397883#M174472</guid>
      <dc:creator>kligms</dc:creator>
      <dc:date>2018-11-20T13:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I append event(s) fields to a separate event based on two timestamps?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397884#M174473</link>
      <description>&lt;P&gt;It looks like there are additional values that must be used to correlate the events?&lt;BR /&gt;
Is the 'id' field shown sufficient to associate Set B with Set A data or field 'vehicle_vin' or a combination of both?&lt;BR /&gt;
The sample data you provided would not correlate any values as the time for Set B data is not within any of Set A event time ranges. The second event, the end_time is before the start_time??? Guess you hand generated this?&lt;BR /&gt;
Are you trying to achieve an association of the lat/long with the start and end times? Is that the goal?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:10:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397884#M174473</guid>
      <dc:creator>laurie_gellatly</dc:creator>
      <dc:date>2020-09-29T22:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I append event(s) fields to a separate event based on two timestamps?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397885#M174474</link>
      <description>&lt;P&gt;Try this (assuming that 'timestamp' field is actually extracted):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index="your_index" 
    | strcat timestamp ";" latitude ";" longitude latv
    | eventstats values(latv) as latv by vehicle_vin 
    | where trip_start_time=trip_start_time 
    | mvexpand latv
    | rex field=latv "(?&amp;lt;timestmp&amp;gt;[^;]*);(?&amp;lt;latitude&amp;gt;[^;]*);(?&amp;lt;longitude&amp;gt;.*)"
    | eval ts = strptime(timestmp,"%Y-%m-%dT%H:%M:%S") 
    | eval trip_start_time = strptime(trip_start_time ,"%Y-%m-%dT%H:%M:%S") 
    | eval trip_end_time = strptime(trip_end_time ,"%Y-%m-%dT%H:%M:%S") 
    | where ts&amp;gt;=trip_start_time AND ts &amp;lt;=trip_end_time
    | table trip_distance_km trip_start_time ts trip_end_time vehicle_vin latitude
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The evals would not be needed if the timestamps are already able to be numerically compared.&lt;BR /&gt;
If you need to keep additional fields from the coordinate events then add them to the strcat and the rex lines.&lt;/P&gt;

&lt;P&gt;...Laurie:{)&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 23:52:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-append-event-s-fields-to-a-separate-event-based-on-two/m-p/397885#M174474</guid>
      <dc:creator>laurie_gellatly</dc:creator>
      <dc:date>2018-11-21T23:52:34Z</dc:date>
    </item>
  </channel>
</rss>

