<?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 How to join two savedsearches based on a column and do a time comparison? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623291#M216671</link>
    <description>&lt;P&gt;I have two savedsearches&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;savedsearch1&lt;/STRONG&gt;: | basesearch | stats count by _time, LocationId&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;savedsearch2&lt;/STRONG&gt;: | basesearch | count by _time, LocationId&lt;/P&gt;
&lt;P&gt;I want to track monitoring LocationIds based on below criteria&lt;BR /&gt;1) LocationIds which are present in savedsearch2 but not in savedsearch1&lt;BR /&gt;2) LocationId if present in both reports, include those LocationIds with savedsearch1 timestamp&amp;gt;savedsearch2 timestamp, otherwise exclude it&lt;/P&gt;
&lt;P&gt;I could get LocationIds which are only present in savedsearch2 using below query, but not able to make time comparison&lt;/P&gt;
&lt;P&gt;##################################################&lt;/P&gt;
&lt;P&gt;| savedsearch "savedsearch1"&lt;BR /&gt;| eval flag="match"&lt;BR /&gt;| append maxtime=1800 timeout=1800&lt;BR /&gt;[ savedsearch "savedsearch2"&lt;BR /&gt;| eval flag="metric"]&lt;BR /&gt;| stats values(flag) as flag by LocationId | where flag="metric" and flag!="match"&lt;BR /&gt;| table LocationId&lt;/P&gt;
&lt;P&gt;##################################################&lt;/P&gt;
&lt;P&gt;Any help would be appreciated!&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2022 17:05:06 GMT</pubDate>
    <dc:creator>Splunk_321</dc:creator>
    <dc:date>2022-12-05T17:05:06Z</dc:date>
    <item>
      <title>How to join two savedsearches based on a column and do a time comparison?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623291#M216671</link>
      <description>&lt;P&gt;I have two savedsearches&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;savedsearch1&lt;/STRONG&gt;: | basesearch | stats count by _time, LocationId&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;savedsearch2&lt;/STRONG&gt;: | basesearch | count by _time, LocationId&lt;/P&gt;
&lt;P&gt;I want to track monitoring LocationIds based on below criteria&lt;BR /&gt;1) LocationIds which are present in savedsearch2 but not in savedsearch1&lt;BR /&gt;2) LocationId if present in both reports, include those LocationIds with savedsearch1 timestamp&amp;gt;savedsearch2 timestamp, otherwise exclude it&lt;/P&gt;
&lt;P&gt;I could get LocationIds which are only present in savedsearch2 using below query, but not able to make time comparison&lt;/P&gt;
&lt;P&gt;##################################################&lt;/P&gt;
&lt;P&gt;| savedsearch "savedsearch1"&lt;BR /&gt;| eval flag="match"&lt;BR /&gt;| append maxtime=1800 timeout=1800&lt;BR /&gt;[ savedsearch "savedsearch2"&lt;BR /&gt;| eval flag="metric"]&lt;BR /&gt;| stats values(flag) as flag by LocationId | where flag="metric" and flag!="match"&lt;BR /&gt;| table LocationId&lt;/P&gt;
&lt;P&gt;##################################################&lt;/P&gt;
&lt;P&gt;Any help would be appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 17:05:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623291#M216671</guid>
      <dc:creator>Splunk_321</dc:creator>
      <dc:date>2022-12-05T17:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two savedsearches based on a column and do a time comparison?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623317#M216681</link>
      <description>&lt;P&gt;You're unable to compare times because times were discarded by the stats command. You can add them back in this way.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| savedsearch "savedsearch1"
| eval flag="match"
| append maxtime=1800 timeout=1800
[ savedsearch "savedsearch2"
| eval flag="metric"]
| stats values(flag) as flag, min(_time) as _time by LocationId 
| where flag="metric" and flag!="match"
| table LocationId&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 05 Dec 2022 19:45:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623317#M216681</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-12-05T19:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two savedsearches based on a column and do a time comparison?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623319#M216682</link>
      <description>&lt;P&gt;You have some pseudo code, so I assume that there is some test SPL that you have tried. Can you explain what problem you encounter?&lt;/P&gt;&lt;P&gt;Just to be clear on terminology so we are on the same page: Splunk classifies a knowledge object that you can reuse in a later &lt;EM&gt;search&lt;/EM&gt; an "&lt;STRONG&gt;advanced search&lt;/STRONG&gt;"; the term "&lt;STRONG&gt;saved searches&lt;/STRONG&gt;" is otherwise called a &lt;U&gt;report&lt;/U&gt;, which you can incorporate into a dashboard but not reuse in another search. The most common reusable advanced search is a &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Definesearchmacros#collapseDesktop15" target="_blank" rel="noopener"&gt;macro&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Assume that you have saved your two searches in macros as "macro1" and "macro2", names being without quotation marks. (If you haven't, read that linked document.) Then, the actual SPL is extremely close to what you posted above:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| `macro1`
| eval flag="match"
| append maxtime=1800 timeout=1800
[ search `macro2` ``` keyword "search" is required in a subsearch ```
| eval flag="metric"]
| stats values(flag) as flag by LocationId | where flag="metric" and flag!="match"
| table LocationId&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 19:51:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623319#M216682</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-12-05T19:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two savedsearches based on a column and do a time comparison?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623384#M216706</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&lt;/P&gt;&lt;P&gt;Thanks for your response. I don't want to get min of time out of those two locationIds. The moment I see LocationId in both the reports, I want to ensure that savedsearch1._time &amp;gt; savedsearch2._time.&lt;/P&gt;&lt;P&gt;In a simple coding language it could be.....&lt;/P&gt;&lt;P&gt;################################################&lt;/P&gt;&lt;P&gt;var LocationIdList;&lt;/P&gt;&lt;P&gt;//add if it is present in savedsearch2 but not in savedsearch1&lt;/P&gt;&lt;P&gt;if(savedsearch2.contains(LocationId) &amp;amp;&amp;amp; !savedsearch1.contains(LocationId)){&lt;/P&gt;&lt;P&gt;LocationIdList.add(LocationId);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;//if it is present in both&lt;/P&gt;&lt;P&gt;if (savedsearch2.contains(LocationId) &amp;amp;&amp;amp; savedsearch1.contains(LocationId)){&lt;/P&gt;&lt;P&gt;//add only when savedsearch1 occurs later than savedsearch2&lt;/P&gt;&lt;P&gt;if (savedsearch1._time&amp;gt;savedsearch2._time){&lt;/P&gt;&lt;P&gt;LocationIdList.add(LocationId);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;################################################&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 11:40:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623384#M216706</guid>
      <dc:creator>Splunk_321</dc:creator>
      <dc:date>2022-12-06T11:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two savedsearches based on a column and do a time comparison?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623440#M216725</link>
      <description>&lt;P&gt;To keep the _time field from both searches, it's necessary to rename the field in one or both searches before combining the results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| savedsearch "savedsearch1"
| eval flag="match"
| rename _time as time1
| append maxtime=1800 timeout=1800
  [ savedsearch "savedsearch2"
  | eval flag="metric"
  | rename _time as time2
  ]
| stats values(*) as * by LocationId 
| where (flag="metric" AND flag!="match" AND time1 &amp;gt; time2)
| table LocationId time1 time2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 13:29:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623440#M216725</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-12-07T13:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two savedsearches based on a column and do a time comparison?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623544#M216758</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp; Thanks for your reply.&lt;/P&gt;&lt;P&gt;I tried something like below, but what I realized is stats command is only propagating only LocationId and flag fields and hiding the time. Hence not able to make time comparison. If I check matches_time, metrics_time fields after stats command, those are blank.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| savedsearch "savedsearch1" 
| eval flag="match" 
| rename _time as matches_time
| append maxtime=1800 timeout=1800 
    [ savedsearch "savedsearch2"
    | eval flag="metric" 
    | rename _time as metrics_time] 
| stats values(flag) as flag by LocationId 
| where (flag="metric" and flag!="match") or (flag="metric" and flag="match" and metrics_time&amp;lt;matches_time) 
| table LocationId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Is there any other way to achieve this. May be a different one rather than append mechanism.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 08:30:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623544#M216758</guid>
      <dc:creator>Splunk_321</dc:creator>
      <dc:date>2022-12-07T08:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two savedsearches based on a column and do a time comparison?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623572#M216769</link>
      <description>&lt;P&gt;My mistake.&amp;nbsp; I've corrected my answer.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 13:29:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-savedsearches-based-on-a-column-and-do-a-time/m-p/623572#M216769</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-12-07T13:29:29Z</dc:date>
    </item>
  </channel>
</rss>

