<?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 Adding additional column after grouping for JSON records in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304281#M57394</link>
    <description>&lt;P&gt;The incoming logs are stored in Splunk in a JSON format.&lt;/P&gt;

&lt;P&gt;Example JSON records below.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Entry 1 :&lt;/STRONG&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{   data:[
    {
      "endpoint":"ep_1",
      "service":"service_1",
      "http_status_code":"500"
    },
    {
      "endpoint":"ep_2",
      "service":"service_1",
      "http_status_code":"500"
    },
    {
      "endpoint":"ep_3",
      "service":"service_2",
      "http_status_code":"503"
    }   ] }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Entry 2 :&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
  data:[
    {
      "endpoint":"ep_1",
      "service":"service_1",
      "http_status_code":"500"
    }
  ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The expected output for my search should be something like : &lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3655iB37DB30EEF9625C1/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;When I search using the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=mashery_production "data{}.http_status_code"= 5*| eval endpoint='data{}.endpoint' | eval service='data{}.service' | Stats Count("data{}.status") as Count, values(service), by endpoint | where Error_Count &amp;gt; 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the output I get is : &lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3656iD9DF2EE3DBD75EB7/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;which looks like the grouping is messed up. Please help.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Oct 2017 07:31:46 GMT</pubDate>
    <dc:creator>technie101</dc:creator>
    <dc:date>2017-10-12T07:31:46Z</dc:date>
    <item>
      <title>Adding additional column after grouping for JSON records</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304281#M57394</link>
      <description>&lt;P&gt;The incoming logs are stored in Splunk in a JSON format.&lt;/P&gt;

&lt;P&gt;Example JSON records below.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Entry 1 :&lt;/STRONG&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{   data:[
    {
      "endpoint":"ep_1",
      "service":"service_1",
      "http_status_code":"500"
    },
    {
      "endpoint":"ep_2",
      "service":"service_1",
      "http_status_code":"500"
    },
    {
      "endpoint":"ep_3",
      "service":"service_2",
      "http_status_code":"503"
    }   ] }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Entry 2 :&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
  data:[
    {
      "endpoint":"ep_1",
      "service":"service_1",
      "http_status_code":"500"
    }
  ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The expected output for my search should be something like : &lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3655iB37DB30EEF9625C1/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;When I search using the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=mashery_production "data{}.http_status_code"= 5*| eval endpoint='data{}.endpoint' | eval service='data{}.service' | Stats Count("data{}.status") as Count, values(service), by endpoint | where Error_Count &amp;gt; 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the output I get is : &lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3656iD9DF2EE3DBD75EB7/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;which looks like the grouping is messed up. Please help.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 07:31:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304281#M57394</guid>
      <dc:creator>technie101</dc:creator>
      <dc:date>2017-10-12T07:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding additional column after grouping for JSON records</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304282#M57395</link>
      <description>&lt;PRE&gt;&lt;CODE&gt; host=mashery_production "data{}.http_status_code"= inactive | eval endpoint='data{}.endpoint' | eval service='data{}.service' | Stats Count("data{}.status") as Count by endpoint, service | where Error_Count &amp;gt; 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Perhaps? Using the values function is expected to provide multiple values, if you are trying to get a count with a value per endpoint/service then you would write something like the above...&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 12:02:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304282#M57395</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2017-10-12T12:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Adding additional column after grouping for JSON records</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304283#M57396</link>
      <description>&lt;P&gt;HI technie101&lt;/P&gt;

&lt;P&gt;Can you please try below search??&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=mashery_production "data{}.http_status_code"= inactive 
| rename data{}.endpoint as endpoint, data{}.service as service, data{}.status as status
| eval tempField=mvzip(mvzip(endpoint,service),status) 
| stats count by _time,tempField 
| eval endpoint=mvindex(split(tempField,","),0), service=mvindex(split(tempField,","),1), status=mvindex(split(tempField,","),1)
| search status="inactive"
| stats count by endpoint,service
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 12:56:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304283#M57396</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-10-12T12:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Adding additional column after grouping for JSON records</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304284#M57397</link>
      <description>&lt;P&gt;Hi Kamlesh,&lt;/P&gt;

&lt;P&gt;I had wrongly typed the json response which was not matching with the search query that I gave. Apologies. I've updated it now.&lt;/P&gt;

&lt;P&gt;Coming to this suggestion, I've tried with the below and I don't see any results.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=mashery_production "data{}.http_status_code"= 5* 
 | rename data{}.endpoint_name as endpoint, data{}.service_name as service, data{}.http_status_code as status
 | eval tempField=mvzip(mvzip(endpoint,service),status) 
 | stats count by _time,tempField 
 | eval endpoint=mvindex(split(tempField,","),0), service=mvindex(split(tempField,","),1), status=mvindex(split(tempField,","),1)
 | search status="5*"
 | stats count by endpoint,service
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 15:23:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304284#M57397</guid>
      <dc:creator>technie101</dc:creator>
      <dc:date>2017-10-12T15:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding additional column after grouping for JSON records</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304285#M57398</link>
      <description>&lt;P&gt;Quick Update. I got the below working.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=mashery_production "data{}.http_status_code"= 5* 
 | rename data{}.endpoint_name as endpoint, data{}.service_name as service, data{}.http_status_code as status | eval tempField=mvzip(mvzip(endpoint,service),status) | eval endpoint=mvindex(split(tempField,","),0), service=mvindex(split(tempField,","),1), status=mvindex(split(tempField,","),2)  | stats count by endpoint,service
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The 2 changes were : &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Corrected the index on the last split on the temp field for status from 1 to 2. That must have been a type.&lt;/LI&gt;
&lt;LI&gt;Removed search status="5*"&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Thanks a lot for the help.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 15:41:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304285#M57398</guid>
      <dc:creator>technie101</dc:creator>
      <dc:date>2017-10-12T15:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding additional column after grouping for JSON records</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304286#M57399</link>
      <description>&lt;P&gt;HI technie101,&lt;BR /&gt;
Great, &lt;BR /&gt;
If It helps you then can you please accept this answer to close this question ??&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 04:40:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Adding-additional-column-after-grouping-for-JSON-records/m-p/304286#M57399</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-10-13T04:40:31Z</dc:date>
    </item>
  </channel>
</rss>

