<?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 use IF....ELSE in Splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654965#M226251</link>
    <description>&lt;P&gt;Describing problems in generic terms is not always helpful as it just leads to more questions about what you are trying to do and with what.&lt;/P&gt;&lt;P&gt;For example, one way of interpreting what you have said could be resolved like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;search indexA&amp;gt;
| appendpipe [|stats count as _count | where _count = 0 | search indexB]&lt;/LI-CODE&gt;</description>
    <pubDate>Sun, 20 Aug 2023 08:16:50 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-08-20T08:16:50Z</dc:date>
    <item>
      <title>How to use IF....ELSE in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654962#M226249</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm trying to figure out How can I use kinda if...else condition in my Splunk query.&lt;/P&gt;&lt;P&gt;I've set up two metrics, which are sending data to Splunk. Each matrix have different index value.&amp;nbsp;&lt;BR /&gt;For Example: For Matrix A the index is "index=aData" and for Metric B index is "index=bData". Currently in Splunk I'm seeing duplicate data because both metrics are sending same value. So what I'm trying to achieve is:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;1. First look for data if coming from "index=aData"&lt;BR /&gt;2.&amp;nbsp;If able to see data from index "aData" show me the results&amp;nbsp;&lt;BR /&gt;3. else check the data from "bData" (Not looking for "OR " condition)&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Results should show the data only from 1 index to avoid duplicity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 01:24:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654962#M226249</guid>
      <dc:creator>Newbie_punk</dc:creator>
      <dc:date>2023-08-20T01:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF....ELSE in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654963#M226250</link>
      <description>&lt;P&gt;The best solution will depend on some other characteristics of the two datasets, and what exactly you plan to do with the surviving data. &amp;nbsp;A generic approach, however, is to use exactly "OR". &amp;nbsp;The idea is to retrieve all data, then retain data from one of indices. &amp;nbsp;Suppose you REALLY want to present all raw data (instead of using stats for presentation), you can do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index IN (aData, bData) &amp;lt;other criteria&amp;gt;
| eventstats values(index) as indices
| where index = mvindex(indices, 0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 02:02:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654963#M226250</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-08-20T02:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF....ELSE in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654965#M226251</link>
      <description>&lt;P&gt;Describing problems in generic terms is not always helpful as it just leads to more questions about what you are trying to do and with what.&lt;/P&gt;&lt;P&gt;For example, one way of interpreting what you have said could be resolved like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;search indexA&amp;gt;
| appendpipe [|stats count as _count | where _count = 0 | search indexB]&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 20 Aug 2023 08:16:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654965#M226251</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-08-20T08:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF....ELSE in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654975#M226256</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/259825"&gt;@Newbie_punk&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;SPL (Splunk Programming Language) isn't a procedural language, so you havent a construct like if then else.&lt;/P&gt;&lt;P&gt;But you can assign a value to a field&amp;nbsp; based on the condition you defined, e.g.&lt;/P&gt;&lt;P&gt;if the same field has different name (e.g. metricA and metricB), you can use:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=aData OR index=bData
| eval metric=coalesce(metricA,metricB)
| table metric&lt;/LI-CODE&gt;&lt;P&gt;or use the if condition in the eval command&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=aData OR index=bData
| eval metric=if(index=indexA,metricA,metricB)
| table metric&lt;/LI-CODE&gt;&lt;P&gt;Adapt ths approach to your condition.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 15:20:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-IF-ELSE-in-Splunk/m-p/654975#M226256</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-08-20T15:20:58Z</dc:date>
    </item>
  </channel>
</rss>

