<?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: Case with multiple matches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Case-with-multiple-matches/m-p/338337#M100349</link>
    <description>&lt;P&gt;@maniishpawar, can you please add some sample data where &lt;CODE&gt;Only the first match count is returned&lt;/CODE&gt;?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="some conflict while finding FOREIGN_KEY" 
| append 
    [| makeresults 
    | eval _raw="Event with nonexistingvalue"] 
| eval P_ErrMsg=case(searchmatch("conflict"), "FKEY1"
    ,searchmatch("FOREIGN KEY"), "FKEY"
    ,searchmatch("nonexistingvalue"),"garbagevalue") 
| stats count by P_ErrMsg
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As @DalJeanis has mentioned you should avoid a command like &lt;CODE&gt;| eval _rawtext=_raw&lt;/CODE&gt; to copy raw data over from one field to another. Alternative to Dal's approach, you can also try &lt;CODE&gt;searchmatch()&lt;/CODE&gt; function which matches your criteria against the _raw data. Splunk Documentation for reference: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#searchmatch.28X.29"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#searchmatch.28X.29&lt;/A&gt;&lt;BR /&gt;
PS: Pipes with &lt;CODE&gt;| makeresults&lt;/CODE&gt; and &lt;CODE&gt;| append&lt;/CODE&gt; are used to generate some mock data. You would need to replace with your base search. Also it is better id you added your own mocked up sample events (&lt;CODE&gt;with sensitive information masked or anonymized&lt;/CODE&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="some conflict while finding FOREIGN_KEY" 
| append 
    [| makeresults 
    | eval _raw="Event with nonexistingvalue"]  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 Oct 2017 20:12:59 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-10-30T20:12:59Z</dc:date>
    <item>
      <title>Case with multiple matches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Case-with-multiple-matches/m-p/338335#M100347</link>
      <description>&lt;P&gt;Hello all, &lt;/P&gt;

&lt;P&gt;I am trying this search but it's not working. &lt;BR /&gt;
Only the first match count is returned. &lt;/P&gt;

&lt;P&gt;index=abc*  sourcetype=applogfile&lt;BR /&gt;
| eval _rawtext=_raw&lt;BR /&gt;
| eval P_ErrMsg=case(_rawtext LIKE "%conflict%", "FKEY1", _rawtext like "%FOREIGN KEY%", "FKEY",_rawtext like "%nonexistingvalue%","garbagevalue") &lt;BR /&gt;
| stats count by P_ErrMsg&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Case-with-multiple-matches/m-p/338335#M100347</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2020-09-29T16:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Case with multiple matches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Case-with-multiple-matches/m-p/338336#M100348</link>
      <description>&lt;P&gt;1) &lt;CODE&gt;Case&lt;/CODE&gt;, in pretty much all languages, is equivalent to a nested &lt;CODE&gt;if-then&lt;/CODE&gt; structure.  You don't get multiple answers.&lt;/P&gt;

&lt;P&gt;2) There is no reason to copy the data from &lt;CODE&gt;_raw&lt;/CODE&gt; to &lt;CODE&gt;_rawtext&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;3) A simple rex will pull what you need, then you can change the values after the &lt;CODE&gt;stats&lt;/CODE&gt; command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc* sourcetype=applogfile
| rex "(?&amp;lt;P_ErrMsg&amp;gt;conflict|FOREIGN KEY|nonexistingvalue)" max_match=0
| eval P_ErrMsg=mvdedup(P_ErrMsg)
| stats count by P_ErrMsg
| eval P_ErrMsg=case(P_ErrMsg=="conflict", "FKEY1",  
    P_ErrMsg=="FOREIGN KEY", "FKEY",
    P_ErrMsg=="nonexistingvalue","garbagevalue") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 19:51:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Case-with-multiple-matches/m-p/338336#M100348</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-30T19:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Case with multiple matches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Case-with-multiple-matches/m-p/338337#M100349</link>
      <description>&lt;P&gt;@maniishpawar, can you please add some sample data where &lt;CODE&gt;Only the first match count is returned&lt;/CODE&gt;?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="some conflict while finding FOREIGN_KEY" 
| append 
    [| makeresults 
    | eval _raw="Event with nonexistingvalue"] 
| eval P_ErrMsg=case(searchmatch("conflict"), "FKEY1"
    ,searchmatch("FOREIGN KEY"), "FKEY"
    ,searchmatch("nonexistingvalue"),"garbagevalue") 
| stats count by P_ErrMsg
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As @DalJeanis has mentioned you should avoid a command like &lt;CODE&gt;| eval _rawtext=_raw&lt;/CODE&gt; to copy raw data over from one field to another. Alternative to Dal's approach, you can also try &lt;CODE&gt;searchmatch()&lt;/CODE&gt; function which matches your criteria against the _raw data. Splunk Documentation for reference: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#searchmatch.28X.29"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#searchmatch.28X.29&lt;/A&gt;&lt;BR /&gt;
PS: Pipes with &lt;CODE&gt;| makeresults&lt;/CODE&gt; and &lt;CODE&gt;| append&lt;/CODE&gt; are used to generate some mock data. You would need to replace with your base search. Also it is better id you added your own mocked up sample events (&lt;CODE&gt;with sensitive information masked or anonymized&lt;/CODE&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="some conflict while finding FOREIGN_KEY" 
| append 
    [| makeresults 
    | eval _raw="Event with nonexistingvalue"]  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 20:12:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Case-with-multiple-matches/m-p/338337#M100349</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-30T20:12:59Z</dc:date>
    </item>
  </channel>
</rss>

