<?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: Splunk query for bayesian check in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-query-for-bayesian-check-Why-am-I-getting-error/m-p/644813#M223287</link>
    <description>&lt;P&gt;When your code/pseudo code is already giving error or undesired output, it is best to describe the use case/intention/desire in words. &amp;nbsp;If I understand correctly, you are trying to inject a field&amp;nbsp;&lt;SPAN&gt;isThereAEventBefore based on what you call a subquery; when that query returns a count greater than 0, set&amp;nbsp;isThereAEventBefore to 1, otherwise set to 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The illustrated pseudo code is not how SPL works. (Additionally, the second search which you enclose in parentheses also contains a misplaced quotation mark. &amp;nbsp;It is more probable that your desired second search contains ("found x=*$ on day1" earliest=-1h) instead of ("found x=*$ on day1 earliest=-1h"). &amp;nbsp;Because you didn't say what was the search period of the first search, I also suspect that if the field you wanted is&amp;nbsp;isThereAEventBefore (as oppsosed to isThereAEvent&lt;U&gt;After&lt;/U&gt;), &lt;FONT face="andale mono,times"&gt;earliest&lt;/FONT&gt; should be &lt;FONT face="andale mono,times"&gt;latest&lt;/FONT&gt;. &amp;nbsp;But that I'll leave it to you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is a literal way to implement my speculation of your intention.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;app=my-app "found x=2$ on day1"
| append
    [search app=my-app "found x=*$ on day1" earliest=-1h
    | stats count
    | eval isThereAEventBefore = if(count &amp;gt; 0, 1, 0)]
| eventstats values(isThereAEventBefore) as isThereAEventBefore&lt;/LI-CODE&gt;&lt;P&gt;In this, both append and eventstats are expensive, especially considering the subsearch is so close to the main search.&lt;/P&gt;&lt;P&gt;You can get away from a single index search with no append in order to improve performance. &amp;nbsp;The logic requires some getting used to. &amp;nbsp;You do a broader search to include both index queries, then mark events to separate, perform stats on one set, then filter out that set that you only need for stats. &amp;nbsp;Assuming "earliest=-1h" is still the correct logic for &lt;SPAN&gt;isThereAEventBefore&lt;/SPAN&gt;,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;app=my-app "found x=*$ on day1" earliest=-2h ``` 2h is just an example; any value greater than 1h will do ```
| eval is_before = if((now() - relative_time(now, "-1h")) &amp;lt; 0, 1, 0) ``` mark events within 1h for stats ```
| eventstats sum(is_before) as are_before ``` perform stats on x=*$ ```
| search "found x=2$ on day1" ``` only keep events where x=2$ ```
| eval isThereAEventBefore = if(are_before &amp;gt; 0, 1, 0)&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Sat, 27 May 2023 10:57:54 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-05-27T10:57:54Z</dc:date>
    <item>
      <title>Splunk query for bayesian check- Why am I getting error?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-query-for-bayesian-check-Why-am-I-getting-error/m-p/644770#M223274</link>
      <description>&lt;P&gt;I am trying to refine search based on a sub query, where sub query is not a filter of outer query. I need to check if certain event happend in the past time(which is different from outer query).&lt;BR /&gt;&lt;BR /&gt;Say current logline is :&amp;nbsp; "Timestamp 9am Log:Info found x=2$ on day1"&lt;BR /&gt;&lt;BR /&gt;I want to search something like this:&lt;BR /&gt;app=my-app "found x=2$ on day1"&amp;nbsp; | eval isThereAEventBefore=(subQuery&lt;STRONG&gt; greater than &lt;/STRONG&gt;0, 1, 0)&lt;BR /&gt;&lt;BR /&gt;replace &lt;STRONG&gt;subQuery&lt;/STRONG&gt; with:&amp;nbsp; (app=my-app "found x=*$ on day1 earliest=-1h" | stats count)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i tried to write this query, i s:&lt;/P&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;Error in 'eval' command: The expression is malformed. Expected ).&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 30 May 2023 03:31:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-query-for-bayesian-check-Why-am-I-getting-error/m-p/644770#M223274</guid>
      <dc:creator>mahesh21894</dc:creator>
      <dc:date>2023-05-30T03:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk query for bayesian check</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-query-for-bayesian-check-Why-am-I-getting-error/m-p/644813#M223287</link>
      <description>&lt;P&gt;When your code/pseudo code is already giving error or undesired output, it is best to describe the use case/intention/desire in words. &amp;nbsp;If I understand correctly, you are trying to inject a field&amp;nbsp;&lt;SPAN&gt;isThereAEventBefore based on what you call a subquery; when that query returns a count greater than 0, set&amp;nbsp;isThereAEventBefore to 1, otherwise set to 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The illustrated pseudo code is not how SPL works. (Additionally, the second search which you enclose in parentheses also contains a misplaced quotation mark. &amp;nbsp;It is more probable that your desired second search contains ("found x=*$ on day1" earliest=-1h) instead of ("found x=*$ on day1 earliest=-1h"). &amp;nbsp;Because you didn't say what was the search period of the first search, I also suspect that if the field you wanted is&amp;nbsp;isThereAEventBefore (as oppsosed to isThereAEvent&lt;U&gt;After&lt;/U&gt;), &lt;FONT face="andale mono,times"&gt;earliest&lt;/FONT&gt; should be &lt;FONT face="andale mono,times"&gt;latest&lt;/FONT&gt;. &amp;nbsp;But that I'll leave it to you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is a literal way to implement my speculation of your intention.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;app=my-app "found x=2$ on day1"
| append
    [search app=my-app "found x=*$ on day1" earliest=-1h
    | stats count
    | eval isThereAEventBefore = if(count &amp;gt; 0, 1, 0)]
| eventstats values(isThereAEventBefore) as isThereAEventBefore&lt;/LI-CODE&gt;&lt;P&gt;In this, both append and eventstats are expensive, especially considering the subsearch is so close to the main search.&lt;/P&gt;&lt;P&gt;You can get away from a single index search with no append in order to improve performance. &amp;nbsp;The logic requires some getting used to. &amp;nbsp;You do a broader search to include both index queries, then mark events to separate, perform stats on one set, then filter out that set that you only need for stats. &amp;nbsp;Assuming "earliest=-1h" is still the correct logic for &lt;SPAN&gt;isThereAEventBefore&lt;/SPAN&gt;,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;app=my-app "found x=*$ on day1" earliest=-2h ``` 2h is just an example; any value greater than 1h will do ```
| eval is_before = if((now() - relative_time(now, "-1h")) &amp;lt; 0, 1, 0) ``` mark events within 1h for stats ```
| eventstats sum(is_before) as are_before ``` perform stats on x=*$ ```
| search "found x=2$ on day1" ``` only keep events where x=2$ ```
| eval isThereAEventBefore = if(are_before &amp;gt; 0, 1, 0)&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Sat, 27 May 2023 10:57:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-query-for-bayesian-check-Why-am-I-getting-error/m-p/644813#M223287</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-05-27T10:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk query for bayesian check</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-query-for-bayesian-check-Why-am-I-getting-error/m-p/645308#M223445</link>
      <description>&lt;P&gt;Apologies for not posting query clearly, i was little confused with my usecase &amp;amp; new to splunk as well.&lt;BR /&gt;&lt;BR /&gt;Here is the quick description of use case:&lt;BR /&gt;I would like to flag a splunk record(X) when there exists certain splunk record(Y) in +15mins(future) w.r.t event&amp;nbsp; time of X. This is to filter out some false positives in logs.&lt;BR /&gt;&lt;BR /&gt;Looks like&amp;nbsp;&lt;BR /&gt;-&amp;gt; append accumulates results&lt;BR /&gt;-&amp;gt; and doesn't run a subsearch for every event faced in outer query.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So it felt like i need a map instead of append, below is a sample query:&lt;BR /&gt;&lt;BR /&gt;&amp;lt;common_search&amp;gt; "Inconsistency with item=*, on Date=*"&lt;BR /&gt;| eval pid=itemId, dt=ItemDate, a_latest=_time+900, a_earliest=_time&lt;BR /&gt;| map maxsearches=20000 search='search&amp;nbsp; earliest=\"$a_earliest$\" latest=\"$a_latest$\"&amp;lt;common_search&amp;gt;&amp;nbsp; \"consistent with item=$pid$, on Date=$Dt$\" | stats count | eval isThereAEventBefore=if(count&amp;gt;0, 1, 0)'&lt;BR /&gt;| eventstats values(isThereAEventAfter) as isThereAEventAfter&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;common_search:-&lt;BR /&gt;&lt;/STRONG&gt;index=.. splunk_server_group=.. sourcetype=.. host="*beta*" source="&amp;lt;path&amp;gt;"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Notes:&lt;BR /&gt;-&amp;gt; As i don't future logs handy yet, i was looking back on a random log by hardcoding it in subsearch.&lt;BR /&gt;-&amp;gt; My query seems to be going into queue &amp;amp; after sometime, i get 0 matches. Though i need in future, currently i am checking back in time _time-900. Can i assume it works similarly for future time as well _time+900&lt;BR /&gt;&lt;BR /&gt;could you please help me if i framed query in right fashion w.r.t my use case ? &amp;amp; why its still gives no matches?&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 21:57:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-query-for-bayesian-check-Why-am-I-getting-error/m-p/645308#M223445</guid>
      <dc:creator>mahesh21894</dc:creator>
      <dc:date>2023-05-31T21:57:51Z</dc:date>
    </item>
  </channel>
</rss>

