<?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 to union two time ranges in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658467#M227445</link>
    <description>&lt;P&gt;Splunk commandment #3: Whenever you have the urge to join, purge that thought and restate the problem in clear terms.&lt;/P&gt;&lt;P&gt;Based on the mock codes, your two subsearches contain the exact same terms except one is one hour shorter than the other; the stats is also exactly the same except field name of the output. &amp;nbsp;I sense that the problem you are trying to solve is this: count unique dest_location-dest_ip combinations by src_ip in the two time intervals. &amp;nbsp;Is this correct?&lt;/P&gt;&lt;P&gt;The following is a transliteration of the requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=&amp;lt;index1&amp;gt; src_ip IN (&amp;lt;srcvalues&amp;gt;) AND dest_ip!=&amp;lt;ipvalues&amp;gt; NOT dest_location IN ("&amp;lt;locvalues&amp;gt;") earliest=-24h ```latest=now```
| stats dc(if(_time &amp;lt; relative_time(now(), "-1h"), dest_location . "-" . dest_ip, null())) as oldconnections
 dc(eval(dest_location . "-" . dest_ip)) as allconnections
 by src_ip&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It only performs one index search covering one time interval. &amp;nbsp;This is a lot more efficient than union on two largely overlapping subsearches.&lt;/P&gt;</description>
    <pubDate>Sun, 24 Sep 2023 00:10:06 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-09-24T00:10:06Z</dc:date>
    <item>
      <title>How to union two time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658460#M227443</link>
      <description>&lt;P&gt;I'm trying to UNION two different tables containing info on foreign traffic - the first table is a log with time range earliest=-24h latest=-1h. The second are logs of those same systems for the full 24 hours (earliest=-24h latest=now()). My search:&lt;BR /&gt;&lt;BR /&gt;| union [ search index=&amp;lt;index1&amp;gt; src_ip IN (&amp;lt;srcvalues&amp;gt;) AND dest_ip!=&amp;lt;ipvalues&amp;gt; NOT dest_location IN ("&amp;lt;locvalues&amp;gt;") earliest=-24h latest=-1h&lt;BR /&gt;| eval dest_loc_ip1=dest_location. "-" .dest_ip&lt;BR /&gt;| stats DC(dest_loc_ip1) as oldconnections by src_ip] [ search index=&amp;lt;index1&amp;gt; src_ip IN (&amp;lt;srcvalues&amp;gt;) AND dest_ip!=&amp;lt;ipvalues&amp;gt; NOT dest_location IN ("&amp;lt;locvalues&amp;gt;") earliest=-24h latest=now()&lt;BR /&gt;| eval dest_loc_ip2=dest_location. "-" .dest_ip&lt;BR /&gt;| stats DC(dest_loc_ip2) as allconnections by src_ip] | fields src_ip oldconnections allconnections&lt;BR /&gt;&lt;BR /&gt;I am trying to compare the values of oldconnections vs allconnections for only the original systems (basically a left join), but for some reason, the allconnections shows all null values. I get a similar issue when trying to left join - the allconnections values are not consistent to the values when I run the search by itself. I can run the two searches separately with the expected result, so I'm guessing there's an error in my UNION syntax and ordering.&lt;BR /&gt;&lt;BR /&gt;Thanks for the help!&lt;BR /&gt;-also open to other ways to solve this &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 20:54:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658460#M227443</guid>
      <dc:creator>marshalll3302</dc:creator>
      <dc:date>2023-09-22T20:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to union two time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658467#M227445</link>
      <description>&lt;P&gt;Splunk commandment #3: Whenever you have the urge to join, purge that thought and restate the problem in clear terms.&lt;/P&gt;&lt;P&gt;Based on the mock codes, your two subsearches contain the exact same terms except one is one hour shorter than the other; the stats is also exactly the same except field name of the output. &amp;nbsp;I sense that the problem you are trying to solve is this: count unique dest_location-dest_ip combinations by src_ip in the two time intervals. &amp;nbsp;Is this correct?&lt;/P&gt;&lt;P&gt;The following is a transliteration of the requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=&amp;lt;index1&amp;gt; src_ip IN (&amp;lt;srcvalues&amp;gt;) AND dest_ip!=&amp;lt;ipvalues&amp;gt; NOT dest_location IN ("&amp;lt;locvalues&amp;gt;") earliest=-24h ```latest=now```
| stats dc(if(_time &amp;lt; relative_time(now(), "-1h"), dest_location . "-" . dest_ip, null())) as oldconnections
 dc(eval(dest_location . "-" . dest_ip)) as allconnections
 by src_ip&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It only performs one index search covering one time interval. &amp;nbsp;This is a lot more efficient than union on two largely overlapping subsearches.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 00:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658467#M227445</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-09-24T00:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to union two time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658604#M227481</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks and noted. All your assumptions were correct except: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN&gt;the stats is also exactly the same except field name of the output &lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My target output fields will look like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;Src_ip of systems of the first 23 hours (-24h to -1h)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;count distinct number of dest_location-dest_ip combinations (-24h to -1h)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;count distinct number of dest_location-dest_ip combinations in full last 24hrs (-24h to now())&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;I see the logic of your code and am trying to tweak it so that it will match my target output.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 14:25:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658604#M227481</guid>
      <dc:creator>marshalll3302</dc:creator>
      <dc:date>2023-09-25T14:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to union two time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658620#M227492</link>
      <description>&lt;P&gt;I tried the the following and all values for oldconnection field are coming up as 0, which I'm assuming is due to the if statement returning null for each event.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=&amp;lt;index1&amp;gt; src_ip IN (&amp;lt;srcvalues&amp;gt;) AND dest_ip!=&amp;lt;ipvalues&amp;gt; NOT dest_location IN ("&amp;lt;locvalues&amp;gt;") earliest=-24h latest=now()
| stats dc(if(_time &amp;lt; relative_time(now(), "-1h"), eval(dest_location. "-" .dest_ip), null())) as oldconnections
 dc(eval(dest_location. "-" .dest_ip)) as allconnections
 by src_ip&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 15:51:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658620#M227492</guid>
      <dc:creator>marshalll3302</dc:creator>
      <dc:date>2023-09-25T15:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to union two time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658629#M227497</link>
      <description>&lt;P&gt;The first dc() needs&amp;nbsp; eval() as the main function.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=&amp;lt;index1&amp;gt; src_ip IN (&amp;lt;srcvalues&amp;gt;) AND dest_ip!=&amp;lt;ipvalues&amp;gt; NOT dest_location IN ("&amp;lt;locvalues&amp;gt;") earliest=-24h latest=now()
| stats dc(eval(if(_time &amp;lt; relative_time(now(), "-1h"), dest_location. "-" .dest_ip, null())) as oldconnections
 dc(eval(dest_location. "-" .dest_ip)) as allconnections
 by src_ip&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;For some reason Splunk doesn't print warning about such, perhaps assuming that all terms are strings unless it begins with eval.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 17:17:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658629#M227497</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-09-25T17:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to union two time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658633#M227498</link>
      <description>&lt;P&gt;This did it. Thank you for all your help&amp;nbsp;@Anonymous&amp;nbsp;!!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 17:56:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-union-two-time-ranges/m-p/658633#M227498</guid>
      <dc:creator>marshalll3302</dc:creator>
      <dc:date>2023-09-25T17:56:45Z</dc:date>
    </item>
  </channel>
</rss>

