<?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: where like command in splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/672976#M230470</link>
    <description>&lt;P&gt;You can try something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base_search&amp;gt;
    | eval
        error=coalesce(spath(response, "errors{}"), spath(response, "errors"))
    | fields - response
    ``` extract variables from the error messages ```
    | rex field=error "(?i)sub\s+\'(?&amp;lt;sub&amp;gt;[^\']+)\'"
    | rex field=error "(?i)product\s+id\s+(?&amp;lt;product_id&amp;gt;[^\s]+)"
    | rex field=error "(?i)location\s+id\s+(?&amp;lt;location_id&amp;gt;[^\s]+)"
    | rex field=error "(?i)datetime\s+(?&amp;lt;start_datetime&amp;gt;\w+\s+\d{4}(?:\-\d{2}){2}T\d{2}(?:\:\d{2}){2}(?:\+|\-)\d{2}\:\d{2})"
    ``` replace variables in the error messages to get a standardized set of error messages to do counts against ```
    | eval
        error=replace(replace(replace(replace(error, "(?i)sub\s+\'([^\']+)\'", "sub '***'"), "(?i)product\s+id\s+([^\s]+)", "product id ***"), "(?i)location\s+id\s+([^\s]+)", "location id ***"), "(?i)datetime\s+(\w+\s+\d{4}(?:\-\d{2}){2}T\d{2}(?:\:\d{2}){2}(?:\+|\-)\d{2}\:\d{2})", "datetime ***")
    ``` stats aggregation to get counts of error messages ```
    | stats
        count as count,
        values(sub) as sub,
        values(product_id) as product_id,
        values(location_id) as location_id,
        values(start_datetime) as start_datetime
            by error&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Results should look something like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1704176291787.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28707iE5E67530400CE78A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1704176291787.png" alt="dtburrows3_0-1704176291787.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can see the counts next to the standardized error messages. Also went ahead and carried over all the variables that were replaced in error messages for context.&lt;BR /&gt;&lt;BR /&gt;You could also check out the cluster command as this will give you similar results without having to do all the extractions and replacements in inline SPL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base_search&amp;gt;
    | table _time, response
    | eval
        error=coalesce(spath(response, "errors{}"), spath(response, "errors"))
    | fields - response
    | cluster field=error t=0.4 showcount=true countfield=count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Results will look like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1704176675392.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28708i70855ED39877C73F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1704176675392.png" alt="dtburrows3_0-1704176675392.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The error messages aren't redacted but their counts do line up pretty well to the previous example so the clustering appears to work decently.&lt;BR /&gt;You can read up more on the cluster command here.&lt;BR /&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/Cluster" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/Cluster&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jan 2024 06:30:24 GMT</pubDate>
    <dc:creator>dtburrows3</dc:creator>
    <dc:date>2024-01-02T06:30:24Z</dc:date>
    <item>
      <title>where like command in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/672971#M230468</link>
      <description>&lt;P&gt;i have all the below messages in the "response" field.&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;{"errors": ["Message: Payment failed. Reason: Hi, we attempted to process the transaction but it seems there was an error. Please check your information and try again. If the problem persists please contact your bank."]}&lt;BR /&gt;&lt;BR /&gt;{"errors": ["Unable to retrieve User Profile with sub '2415d' as it does not exist"]}&lt;BR /&gt;&lt;BR /&gt;{"errors": ["Unable to retrieve User Profile with sub 'dfadf' as it does not exist"]}&lt;BR /&gt;&lt;BR /&gt;{"errors": ["Unable to retrieve User Profile with sub 'fdsgad' as it does not exist"]}&lt;BR /&gt;&lt;BR /&gt;{"errors": ["Unallocated LRW seat not found with product id fdafdsaddsfa and start datetime utc 2024-01-06T05:30:00+00:00 and test location id dfafdfa"]}&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;{"errors": ["Unallocated LRW seat not found with product id sfgdfa and start datetime utc 2024-01-06T05:30:00+00:00 and test location id dsfadfsa"]}&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;I wanted to display the result with the count as&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message: Payment failed. Reason: Hi, we attempted to process the transaction but it seems there was an error. Please check your information and try again. If the problem persists please contact your bank.&lt;BR /&gt;&lt;BR /&gt;Unable to retrieve User Profile with sub '***' as it does not exist&lt;BR /&gt;&lt;BR /&gt;Unallocated LRW seat not found with product id *** and start datetime utc 2024-01-06T05:30:00+00:00 and test location id ***&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 04:53:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/672971#M230468</guid>
      <dc:creator>yuvaraj_m91</dc:creator>
      <dc:date>2024-01-02T04:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: where like command in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/672972#M230469</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/262891"&gt;@yuvaraj_m91&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Splunk command "spath"&amp;nbsp;&lt;SPAN&gt;enables you to extract information from the structured data formats XML and JSON&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Command Ref is given here:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/Spath" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/Spath&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Pls let us know if you are able to use the spath command.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;or you could use direct "rex" command extract field values and do the stats&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;or where like command also should be good i think.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;but, the spath is the simplest option i think. pls let us know if you are ok with spath or not, thanks.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 05:49:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/672972#M230469</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2024-01-02T05:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: where like command in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/672976#M230470</link>
      <description>&lt;P&gt;You can try something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base_search&amp;gt;
    | eval
        error=coalesce(spath(response, "errors{}"), spath(response, "errors"))
    | fields - response
    ``` extract variables from the error messages ```
    | rex field=error "(?i)sub\s+\'(?&amp;lt;sub&amp;gt;[^\']+)\'"
    | rex field=error "(?i)product\s+id\s+(?&amp;lt;product_id&amp;gt;[^\s]+)"
    | rex field=error "(?i)location\s+id\s+(?&amp;lt;location_id&amp;gt;[^\s]+)"
    | rex field=error "(?i)datetime\s+(?&amp;lt;start_datetime&amp;gt;\w+\s+\d{4}(?:\-\d{2}){2}T\d{2}(?:\:\d{2}){2}(?:\+|\-)\d{2}\:\d{2})"
    ``` replace variables in the error messages to get a standardized set of error messages to do counts against ```
    | eval
        error=replace(replace(replace(replace(error, "(?i)sub\s+\'([^\']+)\'", "sub '***'"), "(?i)product\s+id\s+([^\s]+)", "product id ***"), "(?i)location\s+id\s+([^\s]+)", "location id ***"), "(?i)datetime\s+(\w+\s+\d{4}(?:\-\d{2}){2}T\d{2}(?:\:\d{2}){2}(?:\+|\-)\d{2}\:\d{2})", "datetime ***")
    ``` stats aggregation to get counts of error messages ```
    | stats
        count as count,
        values(sub) as sub,
        values(product_id) as product_id,
        values(location_id) as location_id,
        values(start_datetime) as start_datetime
            by error&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Results should look something like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1704176291787.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28707iE5E67530400CE78A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1704176291787.png" alt="dtburrows3_0-1704176291787.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can see the counts next to the standardized error messages. Also went ahead and carried over all the variables that were replaced in error messages for context.&lt;BR /&gt;&lt;BR /&gt;You could also check out the cluster command as this will give you similar results without having to do all the extractions and replacements in inline SPL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base_search&amp;gt;
    | table _time, response
    | eval
        error=coalesce(spath(response, "errors{}"), spath(response, "errors"))
    | fields - response
    | cluster field=error t=0.4 showcount=true countfield=count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Results will look like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1704176675392.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28708i70855ED39877C73F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1704176675392.png" alt="dtburrows3_0-1704176675392.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The error messages aren't redacted but their counts do line up pretty well to the previous example so the clustering appears to work decently.&lt;BR /&gt;You can read up more on the cluster command here.&lt;BR /&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/Cluster" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/Cluster&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 06:30:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/672976#M230470</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2024-01-02T06:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: where like command in splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/673100#M230505</link>
      <description>&lt;P&gt;If you do not need the values, you can simplify to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=response path=errors{} output=errors
| mvexpand errors
| rex field=errors mode=sed "s/(\bwith (sub|\w+ id)) (\S+)/\1 */ s/(and \w+ datetime) (\S+ \S+)/\1 */ s/\band test (\w+ id) (\S+)/and test \1 */"
| stats count by errors&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;As&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/263242"&gt;@dtburrows3&lt;/a&gt;&amp;nbsp;points out, you probably do not want to count by individual date_time.&lt;/LI&gt;&lt;LI&gt;errors{} is an array, so you need mvexpand to handle possible multiple values.&lt;/LI&gt;&lt;LI&gt;When substituting multiple values, sed mode is more readable than nested replace.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Using sample input you illustrated, this is the output&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;errors&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Message: Payment failed. Reason: Hi, we attempted to process the transaction but it seems there was an error. Please check your information and try again. If the problem persists please contact your bank.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Unable to retrieve User Profile with sub * as it does not exist&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Unallocated LRW seat not found with product id * and start datetime * and test location id *&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation you can play with and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval response = split("{\"errors\": [\"Message: Payment failed. Reason: Hi, we attempted to process the transaction but it seems there was an error. Please check your information and try again. If the problem persists please contact your bank.\"]}

{\"errors\": [\"Unable to retrieve User Profile with sub '2415d' as it does not exist\"]}

{\"errors\": [\"Unable to retrieve User Profile with sub 'dfadf' as it does not exist\"]}

{\"errors\": [\"Unable to retrieve User Profile with sub 'fdsgad' as it does not exist\"]}

{\"errors\": [\"Unallocated LRW seat not found with product id fdafdsaddsfa and start datetime utc 2024-01-06T05:30:00+00:00 and test location id dfafdfa\"]}

{\"errors\": [\"Unallocated LRW seat not found with product id sfgdfa and start datetime utc 2024-01-06T05:30:00+00:00 and test location id dsfadfsa\"]}", "

")
| mvexpand response
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 07:50:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/where-like-command-in-splunk/m-p/673100#M230505</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-01-03T07:50:36Z</dc:date>
    </item>
  </channel>
</rss>

