<?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 How to create an interesting field &amp;quot;statusCode&amp;quot; and have it sorted by different statusCode values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631061#M219195</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am using a regex to search for a field "statusCode" which could have multiple values, i.e. "200", "400", "500", etc....&amp;nbsp; I am attempting to create an Interesting Field "statusCode" and have it sorted by different statusCode values.&lt;/P&gt;
&lt;P&gt;I am&amp;nbsp; trying to do perform a search using the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;\\Sample Query
index=myCoolIndex cluster_name="myCoolCluster" sourcetype=myCoolSourceType label_app=myCoolAppName ("\"statusCode\"") | rex field=_raw \"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;2\d{2}|4\d{2}|5\d{2})\"?

\\Sample Log (Looks like JSON object, but its a string):
"{
  "correlationId" : "",
  "message" : "",
  "tracePoint" : "",
  "priority" : "",
  "category" : "",
  "elapsed" : 0,
  "locationInfo" : {
    "lineInFile" : "",
    "component" : "",
    "fileName" : "",
    "rootContainer" : ""
  },
  "timestamp" : "",
  "content" : {
    "message" : "",
    "originalError" : {
      "statusCode" : "200",
      "errorPayload" : {
        "error" : ""
      }
    },
    "standardizedError" : {
      "statusCode" : "400",
      "errorPayload" : {
        "errors" : [ {
          "error" : {
            "traceId" : "",
            "errorCode" : "",
            "errorDescription" : "",
            "errorDetails" : ""
          }
        } ]
      }
    },
    "standardizedError" : {
      "statusCode" : "500",
      "errorPayload" : {
        "errors" : [ {
          "error" : {
            "traceId" : "",
            "errorCode" : "",
            "errorDescription" : ""
            "errorDetails" : ""
          }
        } ]
      }
    }
  },
}"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using online regex tools and a sample output of a log I have confirmed the regEx works outside of a Splunk query.&amp;nbsp; I have also gone through numerous Splunk community threads where I have tried different permutations based on suggestions with no luck.&amp;nbsp; Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Feb 2023 21:01:14 GMT</pubDate>
    <dc:creator>dickersons</dc:creator>
    <dc:date>2023-02-15T21:01:14Z</dc:date>
    <item>
      <title>How to create an interesting field "statusCode" and have it sorted by different statusCode values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631061#M219195</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am using a regex to search for a field "statusCode" which could have multiple values, i.e. "200", "400", "500", etc....&amp;nbsp; I am attempting to create an Interesting Field "statusCode" and have it sorted by different statusCode values.&lt;/P&gt;
&lt;P&gt;I am&amp;nbsp; trying to do perform a search using the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;\\Sample Query
index=myCoolIndex cluster_name="myCoolCluster" sourcetype=myCoolSourceType label_app=myCoolAppName ("\"statusCode\"") | rex field=_raw \"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;2\d{2}|4\d{2}|5\d{2})\"?

\\Sample Log (Looks like JSON object, but its a string):
"{
  "correlationId" : "",
  "message" : "",
  "tracePoint" : "",
  "priority" : "",
  "category" : "",
  "elapsed" : 0,
  "locationInfo" : {
    "lineInFile" : "",
    "component" : "",
    "fileName" : "",
    "rootContainer" : ""
  },
  "timestamp" : "",
  "content" : {
    "message" : "",
    "originalError" : {
      "statusCode" : "200",
      "errorPayload" : {
        "error" : ""
      }
    },
    "standardizedError" : {
      "statusCode" : "400",
      "errorPayload" : {
        "errors" : [ {
          "error" : {
            "traceId" : "",
            "errorCode" : "",
            "errorDescription" : "",
            "errorDetails" : ""
          }
        } ]
      }
    },
    "standardizedError" : {
      "statusCode" : "500",
      "errorPayload" : {
        "errors" : [ {
          "error" : {
            "traceId" : "",
            "errorCode" : "",
            "errorDescription" : ""
            "errorDetails" : ""
          }
        } ]
      }
    }
  },
}"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using online regex tools and a sample output of a log I have confirmed the regEx works outside of a Splunk query.&amp;nbsp; I have also gone through numerous Splunk community threads where I have tried different permutations based on suggestions with no luck.&amp;nbsp; Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 21:01:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631061#M219195</guid>
      <dc:creator>dickersons</dc:creator>
      <dc:date>2023-02-15T21:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an interesting field "statusCode" and have it sorted by different statusCode values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631068#M219199</link>
      <description>&lt;P&gt;What is the expected return? &amp;nbsp;In originalError, you have 200, then in standardizedError, you have 400 and 500. Do you want them all or do you want them separate?&lt;/P&gt;&lt;P&gt;I get the feeling that your developer botched the log format when they really intended to be JSON. &amp;nbsp;So, the first action is to perhaps to ask developers to fix log. &amp;nbsp;But even without, spath happens to be able to extract those fields just as well, at least on the illustrated sample.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath
| table content.originalError.statusCode content.standardizedError.statusCode&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;content.originalError.statusCode&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;content.standardizedError.statusCode&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;400&lt;/DIV&gt;&lt;DIV class=""&gt;500&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 15 Feb 2023 21:09:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631068#M219199</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-15T21:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an interesting field "statusCode" and have it sorted by different statusCode values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631072#M219202</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the response, but unfortunately the entirety of the response is in string format not XML or JSON.&amp;nbsp; The content looks like JSON but it is a string which is why I am attempting to us regEx to extract statusCode from the string.&amp;nbsp; I am not too concerned about multiple values as I am going to "dedup" based off another string field extraction for the traceId of the response.&amp;nbsp; Any suggestion regarding the regEx is appreciated.&amp;nbsp; Again the regEx works using regex101, but only fails in a Splunk query.....&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 21:20:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631072#M219202</guid>
      <dc:creator>dickersons</dc:creator>
      <dc:date>2023-02-15T21:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an interesting field "statusCode" and have it sorted by different statusCode values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631074#M219204</link>
      <description>&lt;P&gt;It should return all values....the expected goal is to separate those values by their statusCode.&amp;nbsp; 1 response can have multiple values I am looking to find all of those values and then separate them once they have been categorized as "statusCode".&amp;nbsp; "spath" ONLY work (according to Splunk) with XML and JSON so "spath" is not a way forward as a solution.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 21:31:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631074#M219204</guid>
      <dc:creator>dickersons</dc:creator>
      <dc:date>2023-02-15T21:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an interesting field "statusCode" and have it sorted by different statusCode values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631078#M219206</link>
      <description>&lt;P&gt;It is not completely true that spath only works on conformant JSON; Splunk does try extra hard to deal with uncomformant JSON. &amp;nbsp;The nice thing about spath - even with partially conformant data, is that it gives you the path so you know exactly which segment of the data this value comes from; sometimes it is critical to know.&lt;/P&gt;&lt;P&gt;If you don't want to know the path, you can still use regex and hope that your developer doesn't change format in the future. &amp;nbsp;The command you gave did not quote the regex. &amp;nbsp;I just added quote and it works fine. &amp;nbsp;In the following, I also added max_match to capture all occurrences of the pattern.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex max_match=0 "\"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;2\d{2}|4\d{2}|5\d{2})\""
``` no need to specify field; default is _raw ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 21:50:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631078#M219206</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-15T21:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an interesting field "statusCode" and have it sorted by different statusCode values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631082#M219209</link>
      <description>&lt;P&gt;Had to add a "?" at the end after 2nd to last double quote, but worked like a charm this is a life save.&amp;nbsp; I absolutely understand what you are getting at in terms of using regEx if it were up to me everything would be in structured format.....&amp;nbsp; Thanks again for this assistance it is much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 22:09:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-an-interesting-field-quot-statusCode-quot-and-have/m-p/631082#M219209</guid>
      <dc:creator>dickersons</dc:creator>
      <dc:date>2023-02-15T22:09:54Z</dc:date>
    </item>
  </channel>
</rss>

