<?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 Adding a Field from a Subsearch Using Join - Inaccurate Results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176396#M50657</link>
    <description>&lt;P&gt;I'm trying to add a field to my main search based on the values retrieved from a subsearch.  More specifically, my main search finds all questions posted on my company's community website, and the subsearch finds all responses to questions.  I'm trying to match each question (found from the main search) with its first response (found by sorting the responses by time and dedup'ing the subsearch based on a thread ID).  However, this doesn't seem to be working properly.  Here is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | join thread_object_id [search ... | dedup thread_object_id sortby +activity_ts | eval first_comment_ts=activity_ts | fields thread_object_id first_comment_ts] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run this search, it pairs events from my main search with timestamps for the wrong comments (the first_comment_ts is incorrect), as if the &lt;CODE&gt;dedup thread_object_id sortby +activity_ts&lt;/CODE&gt; didn't sort it properly.  In fact, it matches each &lt;CODE&gt;thread_object_id&lt;/CODE&gt; with the &lt;CODE&gt;first_comment_ts&lt;/CODE&gt; of the 2nd comment instead of the 1st.  &lt;/P&gt;

&lt;P&gt;When I run the subsearch on its own, everything looks fine.  It only displays events that correspond to the first comment of each thread (first appearance of each &lt;CODE&gt;thread_object_id&lt;/CODE&gt; when sorted by &lt;CODE&gt;activity_ts&lt;/CODE&gt;, which is exactly what I want. &lt;/P&gt;

&lt;P&gt;Here's an example event for a bit more clarification.&lt;/P&gt;

&lt;P&gt;Subsearch result:&lt;BR /&gt;
&lt;IMG src="http://i.gyazo.com/1d6df4ffe2d6965d29b1df66a28c1b4a.png" alt="alt text" /&gt;&lt;BR /&gt;
Main search result (after being joined with the subsearch):&lt;BR /&gt;
&lt;IMG src="http://i.gyazo.com/127d786bf52a9f611208d6605401bb73.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Any ideas why the &lt;CODE&gt;join&lt;/CODE&gt; command would be causing these inconsistencies?  Or is there any way I could do this more efficiently, perhaps without using &lt;CODE&gt;join&lt;/CODE&gt;?  I'm sort of at a loss here.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 20:22:47 GMT</pubDate>
    <dc:creator>rescobar713</dc:creator>
    <dc:date>2020-09-28T20:22:47Z</dc:date>
    <item>
      <title>Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176396#M50657</link>
      <description>&lt;P&gt;I'm trying to add a field to my main search based on the values retrieved from a subsearch.  More specifically, my main search finds all questions posted on my company's community website, and the subsearch finds all responses to questions.  I'm trying to match each question (found from the main search) with its first response (found by sorting the responses by time and dedup'ing the subsearch based on a thread ID).  However, this doesn't seem to be working properly.  Here is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | join thread_object_id [search ... | dedup thread_object_id sortby +activity_ts | eval first_comment_ts=activity_ts | fields thread_object_id first_comment_ts] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run this search, it pairs events from my main search with timestamps for the wrong comments (the first_comment_ts is incorrect), as if the &lt;CODE&gt;dedup thread_object_id sortby +activity_ts&lt;/CODE&gt; didn't sort it properly.  In fact, it matches each &lt;CODE&gt;thread_object_id&lt;/CODE&gt; with the &lt;CODE&gt;first_comment_ts&lt;/CODE&gt; of the 2nd comment instead of the 1st.  &lt;/P&gt;

&lt;P&gt;When I run the subsearch on its own, everything looks fine.  It only displays events that correspond to the first comment of each thread (first appearance of each &lt;CODE&gt;thread_object_id&lt;/CODE&gt; when sorted by &lt;CODE&gt;activity_ts&lt;/CODE&gt;, which is exactly what I want. &lt;/P&gt;

&lt;P&gt;Here's an example event for a bit more clarification.&lt;/P&gt;

&lt;P&gt;Subsearch result:&lt;BR /&gt;
&lt;IMG src="http://i.gyazo.com/1d6df4ffe2d6965d29b1df66a28c1b4a.png" alt="alt text" /&gt;&lt;BR /&gt;
Main search result (after being joined with the subsearch):&lt;BR /&gt;
&lt;IMG src="http://i.gyazo.com/127d786bf52a9f611208d6605401bb73.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Any ideas why the &lt;CODE&gt;join&lt;/CODE&gt; command would be causing these inconsistencies?  Or is there any way I could do this more efficiently, perhaps without using &lt;CODE&gt;join&lt;/CODE&gt;?  I'm sort of at a loss here.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:22:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176396#M50657</guid>
      <dc:creator>rescobar713</dc:creator>
      <dc:date>2020-09-28T20:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176397#M50658</link>
      <description>&lt;P&gt;Hello!  add the &lt;CODE&gt;type=inner&lt;/CODE&gt; to the join command.  Some thing like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | join type= inner thread_object_id [search ... | dedup thread_object_id sortby +activity_ts | eval first_comment_ts=activity_ts | fields thread_object_id first_comment_ts] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2015 16:57:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176397#M50658</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2015-06-25T16:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176398#M50659</link>
      <description>&lt;P&gt;Consider using &lt;CODE&gt;stats&lt;/CODE&gt; to merge your two sourcetypes.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html"&gt;http://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2015 17:01:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176398#M50659</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-25T17:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176399#M50660</link>
      <description>&lt;P&gt;Specifying &lt;CODE&gt;type=inner&lt;/CODE&gt; won't change anything because that's the default setting.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2015 17:02:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176399#M50660</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-25T17:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176400#M50661</link>
      <description>&lt;P&gt;Yeah, I still get the same results.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2015 18:02:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176400#M50661</guid>
      <dc:creator>rescobar713</dc:creator>
      <dc:date>2015-06-25T18:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176401#M50662</link>
      <description>&lt;P&gt;The events in both the main search and the subsearch have the same sourcetype.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2015 18:07:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176401#M50662</guid>
      <dc:creator>rescobar713</dc:creator>
      <dc:date>2015-06-25T18:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176402#M50663</link>
      <description>&lt;P&gt;That's no problem. Something along these lines should do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=foo (question OR comment) | eventstats earliest(activity_ts) as first_comment_ts by thread_object_id | search question
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The initial &lt;CODE&gt;search&lt;/CODE&gt; picks out both types of events, questions and comments. The &lt;CODE&gt;eventstats&lt;/CODE&gt; copies the earliest occurrence of an &lt;CODE&gt;activity_ts&lt;/CODE&gt;  over to all events for each &lt;CODE&gt;thread_object_id&lt;/CODE&gt; (note: I've assumed that questions don't have this field. If they do you need to do a bit of reshuffling to select the correct events.). The final &lt;CODE&gt;search&lt;/CODE&gt; throws out the comments from the final results.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 07:32:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176402#M50663</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-26T07:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176403#M50664</link>
      <description>&lt;P&gt;Hey, that looks like it could work.  However, both questions and responses have the activity_ts field.  How would you suggest I shuffle things around to account for this?  Just for some clarification, I want to find the earliest activity_ts out of the response events, and use those results populate the first_comment_ts field in the question events.  I've tried to tinker with it but my solutions just seem overly convoluted.&lt;/P&gt;

&lt;P&gt;Sorry for the late response.  Thank you so much for your help so far. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:25:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176403#M50664</guid>
      <dc:creator>rescobar713</dc:creator>
      <dc:date>2020-09-28T20:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Field from a Subsearch Using Join - Inaccurate Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176404#M50665</link>
      <description>&lt;P&gt;You could split your single field into two fields like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval question_ts = case(searchmatch("question"), activity_ts) | eval comment_ts = case(searchmatch("comment"), activity_ts) | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jun 2015 20:05:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-Field-from-a-Subsearch-Using-Join-Inaccurate-Results/m-p/176404#M50665</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-30T20:05:44Z</dc:date>
    </item>
  </channel>
</rss>

