<?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: Count matches between values from two different events with different time ranges in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149865#M41951</link>
    <description>&lt;P&gt;You're right, _time does not survive the stats command.  If your data will allow it, you can try &lt;CODE&gt;stats first(DeviceId) as DeviceId, first(_time) as Time&lt;/CODE&gt; to get both the device name and the time it arrived.  This will only work if the first event has a DeviceId field.&lt;/P&gt;

&lt;P&gt;Then you can see how old Time is this way: &lt;CODE&gt;... | eval SevenDaysAgo=relative_time(now(), "-7d") | where Time&amp;gt;SevenDaysAgo | ...&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 20:18:01 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-09-28T20:18:01Z</dc:date>
    <item>
      <title>Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149862#M41948</link>
      <description>&lt;P&gt;Okay, this is a bit difficult to explain, which is also why I'm not sure it hasn't already been answered, but here goes:&lt;/P&gt;

&lt;P&gt;I have two searches:&lt;/P&gt;

&lt;P&gt;The first checks 30-60 days back:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=server* Identifier=name EventType=Stuff 
| stats count AS occurences by DeviceId 
| eval occur=case(occurences &amp;gt;= 2 AND occurences &amp;lt;=3, "true") 
| stats count(occur) AS "Happened 2-3 times"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this one checks 7 days back:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=server* Identifier=name EventType=Stuff earliest=-7d@
| stats dc(DeviceId) AS happened_once
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I need is a count of &lt;CODE&gt;DeviceId&lt;/CODE&gt;'s that match both. That is, they occur 2-3 times the last 30 or 60 days (haven't decided), but at least one of those occurrences, happened in the last 7 days.&lt;/P&gt;

&lt;P&gt;I tried to something with subsearches, but I can't seem to get the syntax right, or I'm going about it the wrong way.&lt;/P&gt;

&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2015 12:55:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149862#M41948</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-12T12:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149863#M41949</link>
      <description>&lt;P&gt;Have a look at the first() and latest() options to the &lt;CODE&gt;stats&lt;/CODE&gt; command.  They will get you the most recent DeviceId.  Then you should be able to examine _time for that event to see if it occurred in the last 7 days.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2015 13:32:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149863#M41949</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-06-12T13:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149864#M41950</link>
      <description>&lt;P&gt;That's a good idea. Could you elaborate a little on how to do this? If I use the first() or last() command, I seem to only get a single value. And as far as I know, stats discards timestamps.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2015 12:29:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149864#M41950</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-15T12:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149865#M41951</link>
      <description>&lt;P&gt;You're right, _time does not survive the stats command.  If your data will allow it, you can try &lt;CODE&gt;stats first(DeviceId) as DeviceId, first(_time) as Time&lt;/CODE&gt; to get both the device name and the time it arrived.  This will only work if the first event has a DeviceId field.&lt;/P&gt;

&lt;P&gt;Then you can see how old Time is this way: &lt;CODE&gt;... | eval SevenDaysAgo=relative_time(now(), "-7d") | where Time&amp;gt;SevenDaysAgo | ...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:18:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149865#M41951</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-09-28T20:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149866#M41952</link>
      <description>&lt;P&gt;another more straight forward approach is to use something like this &lt;A href="http://answers.splunk.com/answers/153336/is-it-possible-to-use-earliest-twice-in-one-search.html"&gt;http://answers.splunk.com/answers/153336/is-it-possible-to-use-earliest-twice-in-one-search.html&lt;/A&gt; - please make sure to pay attention to the last comment.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2015 21:49:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149866#M41952</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-06-15T21:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149867#M41953</link>
      <description>&lt;P&gt;Hi Hartmannish &lt;BR /&gt;
Use &lt;STRONG&gt;set&lt;/STRONG&gt; command with &lt;STRONG&gt;intersect&lt;/STRONG&gt; operation&lt;BR /&gt;
Try this search code &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|set intersect [search  host=server* Identifier=name EventType=Stuff  earliest=-60d@ ][search   host=server* Identifier=name EventType=Stuff earliest=-7d@  ]|stats count(DeviceId ) as count_DeviceId 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jun 2015 10:24:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149867#M41953</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2015-06-16T10:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149868#M41954</link>
      <description>&lt;P&gt;I must admit, I simply am not fluent enough in splunk to understand how this helps me? Is "Device" different from "DeviceId"? Also, how does this work together with my eval case() command?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 11:01:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149868#M41954</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-16T11:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149869#M41955</link>
      <description>&lt;P&gt;I guess I'm in the same dilemma here as I was with richgalloway's suggestion. I simply don't understand where to start. How do I translate what your link says, to my issue?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 11:02:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149869#M41955</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-16T11:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149870#M41956</link>
      <description>&lt;P&gt;What about my answer .Let examine it.And tell if it works &lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 12:15:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149870#M41956</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2015-06-16T12:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149871#M41957</link>
      <description>&lt;P&gt;It looks REALLY close to what I need, but I havn't been able to test it, since I'm having some local IT issues &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I will defnitely get back once I get to try it for real.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 12:24:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149871#M41957</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-16T12:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149872#M41958</link>
      <description>&lt;P&gt;Device and DeviceId are the same.  I've edited my comment to use only DeviceId.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 12:37:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149872#M41958</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-06-16T12:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149873#M41959</link>
      <description>&lt;P&gt;Okay, seems I simply can't use the set intersect command. It always returns either exactly 10000, or 1, or 2, if I try to use dc(). Maybe there are some limitations to set intersect I don't understand.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 13:05:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149873#M41959</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-16T13:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149874#M41960</link>
      <description>&lt;P&gt;Have you tried to use &lt;CODE&gt;append&lt;/CODE&gt; to output your second command to your first command ?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 13:15:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149874#M41960</guid>
      <dc:creator>echozero39</dc:creator>
      <dc:date>2015-06-16T13:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149875#M41961</link>
      <description>&lt;P&gt;Retry with &lt;STRONG&gt;union&lt;/STRONG&gt; operation and add the expression &lt;STRONG&gt;|fields DeviceId&lt;/STRONG&gt;  in each subsearch &lt;/P&gt;

&lt;P&gt;Try this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |set union [search  host=server* Identifier=name EventType=Stuff  earliest=-60d@|fields DeviceId  ][search   host=server* Identifier=name EventType=Stuff earliest=-7d@|fields DeviceId ]|stats count(DeviceId ) as count_DeviceId 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Don't add something else in the query &lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 13:45:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149875#M41961</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2015-06-16T13:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149876#M41962</link>
      <description>&lt;P&gt;Same issue, except I get 20000 now instead of 10000 &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 14:41:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149876#M41962</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-16T14:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149877#M41963</link>
      <description>&lt;P&gt;Okay, thanks for the clarification &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Still, I'm not quite sure how to fill in the blanks from your explanation &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I'm not trying to make you do my work for me, there are just a lot of things I still don't understand about splunk &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 14:49:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149877#M41963</guid>
      <dc:creator>Hartmannish</dc:creator>
      <dc:date>2015-06-16T14:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count matches between values from two different events with different time ranges</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149878#M41964</link>
      <description>&lt;P&gt;I was trying to come up with a way to do the job with a single search.  On further study, I believe my suggestion won't solve both parts of your problem.  Sorry.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2015 15:02:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-matches-between-values-from-two-different-events-with/m-p/149878#M41964</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-06-16T15:02:23Z</dc:date>
    </item>
  </channel>
</rss>

