<?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: Extracting fields and times as nested table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540371#M152876</link>
    <description>&lt;P&gt;I'm not completely following what you're asking, but there are definitely some things to fix.&lt;/P&gt;&lt;P&gt;When you use | makeresults, it automatically creates a _time field equal to the current time. That is the "time" field that you are trying to manipulate (which is the same for every row). What you're looking for is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;           | makeresults | eval _raw = "2021-02-17 09:09:50 Calculated ABC. Action took 100 milliseconds"
| append [ | makeresults | eval _raw = "2021-02-17 10:09:50 Calculated XYZ. Action took 122450 milliseconds" ]
| append [ | makeresults | eval _raw = "2021-02-17 11:09:50 Calculated ABC. Action took 10 milliseconds"     ]
| append [ | makeresults | eval _raw = "2021-02-17 12:09:50 Calculated XYZ. Action took 67543 milliseconds"  ]
| append [ | makeresults | eval _raw = "2021-02-17 14:09:50 Calculated ABC. Action took 11 milliseconds"     ]
| append [ | makeresults | eval _raw = "2021-02-17 15:09:50 Calculated XYZ. Action took 5 milliseconds"      ]
| append [ | makeresults | eval _raw = "2021-02-17 16:09:50 Calculated ABC. Action took 600 milliseconds"    ]
| rex field=_raw "Calculated (?&amp;lt;ACTION&amp;gt;[^\.]+)\."
| rex field=_raw "Action took (?&amp;lt;DURATION&amp;gt;\d+) milliseconds"
| eval time  = substr(_raw, 0, 20)
| eval _time = strptime(time,  "%F %H:%M:%S")
| eval time  = strftime(_time, "%F %H:%M:%S")
| sort 0 ACTION -DURATION
| streamstats count by ACTION
| where count &amp;lt;= 2
| stats list(DURATION) as "Top 2 Durations", list(time) as Time by ACTION&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep in mind that _time should always be an epoch so you should keep your human-readable time in a non-_time field. That's why I seem to switch back and forth.&lt;/P&gt;&lt;P&gt;As a side note, assigning the _time and the two rex statements should all be done at the sourcetype definition level. You should NOT actually be doing any of this in a search in production.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Data/Createsourcetypes" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/Data/Createsourcetypes&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Feb 2021 12:06:56 GMT</pubDate>
    <dc:creator>jacobpevans</dc:creator>
    <dc:date>2021-02-18T12:06:56Z</dc:date>
    <item>
      <title>Extracting fields and times as nested table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540291#M152840</link>
      <description>&lt;P&gt;I have a log with the following entries among others and I am looking for a way to display the top 2 times by each action.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Calculated ABC. Action took 100 milliseconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Calculated XYZ. Action took 122450 milliseconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Calculated ABC. Action took 10 milliseconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Calculated XYZ. Action took 67543 milliseconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Calculated ABC. Action took 11 milliseconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Calculated XYZ. Action took 5 milliseconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Calculated ABC. Action took 600 milliseconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can extract the fields just fine using regex and can display the entry with max time by action using the below search&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;source="*test.log*" "Calculated" | rex field=_raw "^.*Calculated (?&amp;lt;ACTION&amp;gt;.+)" | rex field=_raw "^.*Action took (?&amp;lt;DURATION&amp;gt;.+) milliseconds" | stats max(DURATION) by ACTION&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;ACTION&lt;/TD&gt;&lt;TD width="50%"&gt;DURATION&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;ABC&lt;/TD&gt;&lt;TD width="50%"&gt;600&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;XYZ&lt;/TD&gt;&lt;TD width="50%"&gt;122450&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I'm lost as to how to get the top 2 transactions reported like below&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;ACTION&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;DURATION&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;ABC&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;600&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;XYZ&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;122450&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;67453&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 17 Feb 2021 17:57:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540291#M152840</guid>
      <dc:creator>v33jay</dc:creator>
      <dc:date>2021-02-17T17:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields and times as nested table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540304#M152846</link>
      <description>&lt;P&gt;Greetings&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231619"&gt;@v33jay&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Try this run-anywhere search using your sample data. I had to change the rex because yours were too aggressive.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;           | makeresults | eval _raw = "Calculated ABC. Action took 100 milliseconds"
| append [ | makeresults | eval _raw = "Calculated XYZ. Action took 122450 milliseconds" ]
| append [ | makeresults | eval _raw = "Calculated ABC. Action took 10 milliseconds" ]
| append [ | makeresults | eval _raw = "Calculated XYZ. Action took 67543 milliseconds" ]
| append [ | makeresults | eval _raw = "Calculated ABC. Action took 11 milliseconds" ]
| append [ | makeresults | eval _raw = "Calculated XYZ. Action took 5 milliseconds" ]
| append [ | makeresults | eval _raw = "Calculated ABC. Action took 600 milliseconds" ]
| rex field=_raw "Calculated (?&amp;lt;ACTION&amp;gt;[^\.]+)\."
| rex field=_raw "Action took (?&amp;lt;DURATION&amp;gt;\d+) milliseconds"

| sort 0 ACTION -DURATION
| streamstats count by ACTION
| where count &amp;lt;= 2
| stats list(DURATION) as "Top 2 Durations" by ACTION&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 17 Feb 2021 19:31:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540304#M152846</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2021-02-17T19:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields and times as nested table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540319#M152852</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/182087"&gt;@jacobpevans&lt;/a&gt;, that worked like a charm!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 21:37:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540319#M152852</guid>
      <dc:creator>v33jay</dc:creator>
      <dc:date>2021-02-17T21:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields and times as nested table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540328#M152855</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/182087"&gt;@jacobpevans&lt;/a&gt;&amp;nbsp;, Can I ask a related question. I would like to extract the time associated with the events as well. I used the below search which is giving me the Time values but the times themselves are sorted in ascending order and not really related to the events with the maximum duration. Any pointers as to what I got wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;          | makeresults | eval _raw = "2021-02-17 09:09:50 Calculated ABC. Action took 100 milliseconds"
| append [ | makeresults | eval _raw = "2021-02-17 10:09:50 Calculated XYZ. Action took 122450 milliseconds" ]
| append [ | makeresults | eval _raw = "2021-02-17 11:09:50 Calculated ABC. Action took 10 milliseconds" ]
| append [ | makeresults | eval _raw = "2021-02-17 12:09:50 Calculated XYZ. Action took 67543 milliseconds" ]
| append [ | makeresults | eval _raw = "2021-02-17 14:09:50 Calculated ABC. Action took 11 milliseconds" ]
| append [ | makeresults | eval _raw = "2021-02-17 15:09:50 Calculated XYZ. Action took 5 milliseconds" ]
| append [ | makeresults | eval _raw = "2021-02-17 16:09:50 Calculated ABC. Action took 600 milliseconds" ]
| rex field=_raw "Calculated (?&amp;lt;ACTION&amp;gt;[^\.]+)\."
| rex field=_raw "Action took (?&amp;lt;DURATION&amp;gt;\d+) milliseconds"
| eval _time = strftime(_time,"%F %H:%M:%S")
| sort 0 ACTION -DURATION
| streamstats count by ACTION
| where count &amp;lt;= 2
| stats list(DURATION) as "Top 2 Durations", values(_time) as Time by ACTION&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 00:09:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540328#M152855</guid>
      <dc:creator>v33jay</dc:creator>
      <dc:date>2021-02-18T00:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields and times as nested table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540371#M152876</link>
      <description>&lt;P&gt;I'm not completely following what you're asking, but there are definitely some things to fix.&lt;/P&gt;&lt;P&gt;When you use | makeresults, it automatically creates a _time field equal to the current time. That is the "time" field that you are trying to manipulate (which is the same for every row). What you're looking for is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;           | makeresults | eval _raw = "2021-02-17 09:09:50 Calculated ABC. Action took 100 milliseconds"
| append [ | makeresults | eval _raw = "2021-02-17 10:09:50 Calculated XYZ. Action took 122450 milliseconds" ]
| append [ | makeresults | eval _raw = "2021-02-17 11:09:50 Calculated ABC. Action took 10 milliseconds"     ]
| append [ | makeresults | eval _raw = "2021-02-17 12:09:50 Calculated XYZ. Action took 67543 milliseconds"  ]
| append [ | makeresults | eval _raw = "2021-02-17 14:09:50 Calculated ABC. Action took 11 milliseconds"     ]
| append [ | makeresults | eval _raw = "2021-02-17 15:09:50 Calculated XYZ. Action took 5 milliseconds"      ]
| append [ | makeresults | eval _raw = "2021-02-17 16:09:50 Calculated ABC. Action took 600 milliseconds"    ]
| rex field=_raw "Calculated (?&amp;lt;ACTION&amp;gt;[^\.]+)\."
| rex field=_raw "Action took (?&amp;lt;DURATION&amp;gt;\d+) milliseconds"
| eval time  = substr(_raw, 0, 20)
| eval _time = strptime(time,  "%F %H:%M:%S")
| eval time  = strftime(_time, "%F %H:%M:%S")
| sort 0 ACTION -DURATION
| streamstats count by ACTION
| where count &amp;lt;= 2
| stats list(DURATION) as "Top 2 Durations", list(time) as Time by ACTION&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep in mind that _time should always be an epoch so you should keep your human-readable time in a non-_time field. That's why I seem to switch back and forth.&lt;/P&gt;&lt;P&gt;As a side note, assigning the _time and the two rex statements should all be done at the sourcetype definition level. You should NOT actually be doing any of this in a search in production.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Data/Createsourcetypes" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/Data/Createsourcetypes&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 12:06:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540371#M152876</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2021-02-18T12:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields and times as nested table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540576#M152938</link>
      <description>&lt;P&gt;That's what I was looking for, Thanks again&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/182087"&gt;@jacobpevans&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 21:05:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-and-times-as-nested-table/m-p/540576#M152938</guid>
      <dc:creator>v33jay</dc:creator>
      <dc:date>2021-02-19T21:05:12Z</dc:date>
    </item>
  </channel>
</rss>

