<?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: Injecting fields into other events? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309559#M92848</link>
    <description>&lt;P&gt;Your phrasing of the issue seems a bit odd - "keep looking for events throughout the search"?  The entire file will be passed once and the values collected.  &lt;CODE&gt;first()&lt;/CODE&gt;, &lt;CODE&gt;earliest()&lt;/CODE&gt;, &lt;CODE&gt;last()&lt;/CODE&gt; and &lt;CODE&gt;latest()&lt;/CODE&gt; will have slightly different effects, with &lt;CODE&gt;first()&lt;/CODE&gt; being marginally more efficient, but the entire file gets passed once, and has to be in Splunk.&lt;/P&gt;

&lt;P&gt;The basic method for this is...&lt;/P&gt;

&lt;P&gt;1) Select all events you might need.&lt;BR /&gt;
2) Roll the A data onto the B records.&lt;BR /&gt;
3) Drop the A records.&lt;BR /&gt;
4) process the B records.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Nov 2017 22:02:20 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-11-30T22:02:20Z</dc:date>
    <item>
      <title>Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309558#M92847</link>
      <description>&lt;P&gt;I have a set of events with the pattern that there's a single event A that pairs with many event Bs (based on a field let's call CorrelationId). The event A has a field I want on all of the B events. The events can come in in any order. We might have the following (event type followed by CorrelationId):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;A (Correlation ID: 1, FieldToInject: 10)
B (Correlation ID: 1)
B (Correlation ID: 1)
B (Correlation ID: 1)
B (Correlation ID: 1)
B (Correlation ID: 2)
B (Correlation ID: 2)
B (Correlation ID: 3) 
A (Correlation ID: 3, FieldToInject: 100)
A (Correlation ID: 2) FieldToInject: 50
B (Correlation ID: 2)
B (Correlation ID: 2)
B (Correlation ID: 3)
B (Correlation ID: 3)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The new output should look like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;A (Correlation ID: 1, FieldToInject: 10)
B (Correlation ID: 1, FieldToInject: 10)
B (Correlation ID: 1, FieldToInject: 10)
B (Correlation ID: 1, FieldToInject: 10)
B (Correlation ID: 1, FieldToInject: 10)
B (Correlation ID: 2, FieldToInject: 50)
B (Correlation ID: 2, FieldToInject: 50)
B (Correlation ID: 3, FieldToInject: 100) 
A (Correlation ID: 3, FieldToInject: 100)
A (Correlation ID: 2) FieldToInject: 50
B (Correlation ID: 2, FieldToInject: 50)
B (Correlation ID: 2, FieldToInject: 50)
B (Correlation ID: 3, FieldToInject: 100)
B (Correlation ID: 3, FieldToInject: 100)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are a couple of ways I can think of to do this. I could use an aggregation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventstats first(FieldToInject1) AS FieldToInject1, first(FieldToInject2) AS FieldToInject2 BY CorrelationId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That works, but I don't imagine is very efficient - I know all of the events will come in in a short window, but this call will keep looking for events from a given CorrelationId throughout the entire search.&lt;/P&gt;

&lt;P&gt;The other obvious option is a transaction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction CorrelationId maxspan=1m
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem here is that, because we more than one B event, I need to play games of zipping of multivalue fields and then mvexpanding to make any sense of things.&lt;/P&gt;

&lt;P&gt;Is there a more natural way folks would recommend attempting to do something like this?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 20:10:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309558#M92847</guid>
      <dc:creator>doweaver</dc:creator>
      <dc:date>2017-11-30T20:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309559#M92848</link>
      <description>&lt;P&gt;Your phrasing of the issue seems a bit odd - "keep looking for events throughout the search"?  The entire file will be passed once and the values collected.  &lt;CODE&gt;first()&lt;/CODE&gt;, &lt;CODE&gt;earliest()&lt;/CODE&gt;, &lt;CODE&gt;last()&lt;/CODE&gt; and &lt;CODE&gt;latest()&lt;/CODE&gt; will have slightly different effects, with &lt;CODE&gt;first()&lt;/CODE&gt; being marginally more efficient, but the entire file gets passed once, and has to be in Splunk.&lt;/P&gt;

&lt;P&gt;The basic method for this is...&lt;/P&gt;

&lt;P&gt;1) Select all events you might need.&lt;BR /&gt;
2) Roll the A data onto the B records.&lt;BR /&gt;
3) Drop the A records.&lt;BR /&gt;
4) process the B records.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 22:02:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309559#M92848</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-11-30T22:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309560#M92849</link>
      <description>&lt;P&gt;Yeah, my phrasing here is a product of my lack of understanding of what's happening under the covers.&lt;/P&gt;

&lt;P&gt;It sounds like you're suggesting the aggregation approach, which should work. The main reason I asked this question is because of a "eureka" moment I had a few months ago. I was doing a lot of gross "stats first(x), first(y) BY Z" on things when I only expected a single event per Z... and then I discovered that the "xyseries" was the "right" way to do that. I was wondering if there's a "right" way to do what I wanted above, but it sounds like aggregating and using "first" is the best there is.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 22:07:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309560#M92849</guid>
      <dc:creator>doweaver</dc:creator>
      <dc:date>2017-11-30T22:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309561#M92850</link>
      <description>&lt;P&gt;The command that you probably need is &lt;CODE&gt;filldown&lt;/CODE&gt; and possibly &lt;CODE&gt;selfjoin&lt;/CODE&gt;.  Take a very careful look at each one and play around.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2017 03:16:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309561#M92850</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-12-02T03:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309562#M92851</link>
      <description>&lt;P&gt;@doweaver, for the sample data provided in the question, can you please state what is the desired output after correlation?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2017 06:11:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309562#M92851</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-02T06:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309563#M92852</link>
      <description>&lt;P&gt;Updated with desired output.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2017 15:30:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309563#M92852</guid>
      <dc:creator>doweaver</dc:creator>
      <dc:date>2017-12-02T15:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309564#M92853</link>
      <description>&lt;P&gt;I don't think &lt;CODE&gt;filldown&lt;/CODE&gt; works - that would blindly insert the most recently seen value for "FieldToInject", which means it would fail when we don't have A followed by all its matching Bs, and repeat.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;selfjoin&lt;/CODE&gt; doesn't seem like the answer here either, since I just want to join A to all Bs, and not Bs to Bs. I'm not seeing anything giving me that flexibility in the doc, but I'll keep looking.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2017 15:34:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309564#M92853</guid>
      <dc:creator>doweaver</dc:creator>
      <dc:date>2017-12-02T15:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309565#M92854</link>
      <description>&lt;P&gt;Your &lt;CODE&gt;eventstats&lt;/CODE&gt; solutions is perfect and I would use that.  If you'd like to experiment, and you are sure that you can isolate an appropriate time window, you could try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | streamstats time_window=200 first(FieldToInject1) AS FieldToInject1, first(FieldToInject2) AS FieldToInject2 BY CorrelationId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Depending on how tightly you can tune it, this could be more efficient but could also be way less so.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2017 16:36:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309565#M92854</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-12-02T16:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Injecting fields into other events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309566#M92855</link>
      <description>&lt;P&gt;@doweaver, I think &lt;CODE&gt;filldown&lt;/CODE&gt; will work for you provided you have sorted your data with Correlation_ID and also sort on events so that event A comes before event B. I have tried following run any where search which mocks the sample data provided in the question and the desired output.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval  data="event=A,Correlation_ID=1,eventToInject=10;event=B,Correlation_ID=1;event=B,Correlation_ID=1;event=B,Correlation_ID=1;event=B,Correlation_ID=1;event=B,Correlation_ID=2;event=B,Correlation_ID=2;event=B,Correlation_ID=3;event=A,Correlation_ID=3,eventToInject=100;event=A,Correlation_ID=2,eventToInject=50;event=B,Correlation_ID=2;event=B,Correlation_ID=2;event=B,Correlation_ID=3;event=B,Correlation_ID=3;"
|  makemv data delim=";"
|  mvexpand data
|  rename data as _raw
|  KV
|  table event Correlation_ID eventToInject
|  sort Correlation_ID event
|  filldown eventToInject
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Dec 2017 16:38:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Injecting-fields-into-other-events/m-p/309566#M92855</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-02T16:38:40Z</dc:date>
    </item>
  </channel>
</rss>

