<?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 Transpose Multi Value Fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Transpose-Multi-Value-Fields/m-p/112669#M29596</link>
    <description>&lt;P&gt;So I'm working on a new App, one that generates summary data based on eventtypes and fields. The summary data looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;03/31/2015 08:20:00 -0400, search_name=kpi_5minute_gen, search_now=1427804700.000, info_min_time=1427804400.000, info_max_time=1427804700.000, info_search_time=1427804701.062, avgmetric_thermostat:_:current_humidity="33.333333", avgmetric_thermostat:_:current_temperature="22.100000", avgmetric_thermostat:_:target_temperature="23.116333", interval=perfiveminute, maxmetric_thermostat:_:current_humidity=34, maxmetric_thermostat:_:current_temperature="22.47", maxmetric_thermostat:_:target_temperature="24.599", minmetric_thermostat:_:current_humidity=33, minmetric_thermostat:_:current_temperature="21.36", minmetric_thermostat:_:target_temperature="22.375", app=mykpi
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I wanted to be able to graph it by each field (here represented by target_temperature, current_humidity, and current_temperature) AND by the metadata contained within the field name itself (here my metric type is "min", "max", "avg") and the correlated eventtype is "thermostat". &lt;/P&gt;

&lt;P&gt;So why not do this, you ask?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart avg(avgmetric_*) as * | rename thermostat:_:* as *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Well, because that doesn't help me perform visualizations on the eventtype. I need my data in a form like this (this is simplified of course):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time             interval       metric_type         eventtype               field                 value
3/20/2014       perfiveminute      avg            thermostat       current_temperature          22.47
3/21/2014       perfiveminute      max          thermostat      current_humidity                 34
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and so on.&lt;/P&gt;

&lt;P&gt;So here's my question: How do I extract metadata from fields and correlate them with their values across several thousand data points while keeping it abstract to apply to each new summary field?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 19:19:21 GMT</pubDate>
    <dc:creator>alacercogitatus</dc:creator>
    <dc:date>2020-09-28T19:19:21Z</dc:date>
    <item>
      <title>Transpose Multi Value Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transpose-Multi-Value-Fields/m-p/112669#M29596</link>
      <description>&lt;P&gt;So I'm working on a new App, one that generates summary data based on eventtypes and fields. The summary data looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;03/31/2015 08:20:00 -0400, search_name=kpi_5minute_gen, search_now=1427804700.000, info_min_time=1427804400.000, info_max_time=1427804700.000, info_search_time=1427804701.062, avgmetric_thermostat:_:current_humidity="33.333333", avgmetric_thermostat:_:current_temperature="22.100000", avgmetric_thermostat:_:target_temperature="23.116333", interval=perfiveminute, maxmetric_thermostat:_:current_humidity=34, maxmetric_thermostat:_:current_temperature="22.47", maxmetric_thermostat:_:target_temperature="24.599", minmetric_thermostat:_:current_humidity=33, minmetric_thermostat:_:current_temperature="21.36", minmetric_thermostat:_:target_temperature="22.375", app=mykpi
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But I wanted to be able to graph it by each field (here represented by target_temperature, current_humidity, and current_temperature) AND by the metadata contained within the field name itself (here my metric type is "min", "max", "avg") and the correlated eventtype is "thermostat". &lt;/P&gt;

&lt;P&gt;So why not do this, you ask?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart avg(avgmetric_*) as * | rename thermostat:_:* as *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Well, because that doesn't help me perform visualizations on the eventtype. I need my data in a form like this (this is simplified of course):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time             interval       metric_type         eventtype               field                 value
3/20/2014       perfiveminute      avg            thermostat       current_temperature          22.47
3/21/2014       perfiveminute      max          thermostat      current_humidity                 34
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and so on.&lt;/P&gt;

&lt;P&gt;So here's my question: How do I extract metadata from fields and correlate them with their values across several thousand data points while keeping it abstract to apply to each new summary field?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:19:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transpose-Multi-Value-Fields/m-p/112669#M29596</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2020-09-28T19:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Multi Value Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transpose-Multi-Value-Fields/m-p/112670#M29597</link>
      <description>&lt;P&gt;Ok, so here is what I came up with.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary app=mykpi | table * | fields avg* max* min* std* interval _time | foreach * [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;_values = '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'.",".interval.","._time] | stats values(*_values) as * | transpose 1000000000|rename column as metric "row 1" as values| eval values = replace(values," ",";") | makemv delim=";" values | mvexpand values | makemv delim="," values | eval value = mvindex(values,0) | eval interval = mvindex(values,1) | eval _time = mvindex(values,2) |  fields _time metric interval value | search NOT metric="interval" | eval a1 = split(metric,":_:") |eval a2=mvindex(a1,0)| rex field=a2 "_(?&amp;lt;eventtype&amp;gt;.*)" | eval metric_type = substr(a2,0,3) | eval metric_type = if(metric_type=="std","stdevp",metric_type) | eval field = mvindex(a1,1) | fields - a1 a2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So let's discuss. This gives us the events in a table form with only the fields I want to use. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary app=mykpi | table * | fields avg* max* min* std* interval _time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This foreach gives us a new field that has the values I want to transition separated by commas. The FIELD on the right side of the eval, when expanded, is actually the value (24 or whatever) that we want. So a line of this looks like: "24.32,perfiveminute,199384330". &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foreach * [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;_values = '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'.",".interval.","._time]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next, stats.  We only really want the new fields, so stats is a quick way to get only those. Transpose takes the columns and rows, and flips them. The rows become columns, and the columns become sharks. No wait, rows. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats values(*_values) as * | transpose 1000000000|rename column as metric "row 1" as values
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We now have a table that looks like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;metric                                   values
avgmetric_thermostat:_:current_humidity 30.666667,perfiveminute,1427806800
avgmetric_thermostat:_:current_temperature  21.460000,perfiveminute,1427806800
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So now, we will split apart each value, make them mulitvalue, expand each multivalue event into single events, and to some evaluations to get our final result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   metric  interval    value   eventtype   field   metric_type
2015-03-31 09:00:00 avgmetric_thermostat:_:current_humidity perfiveminute   30.666667   thermostat  current_humidity    avg
2015-03-31 09:00:00 avgmetric_thermostat:_:current_temperature  perfiveminute   21.460000   thermostat current_temperature  avg
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So simple! well, maybe not. But that's how I did it. Anyone see some optimizations?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2015 13:10:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transpose-Multi-Value-Fields/m-p/112670#M29597</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2015-03-31T13:10:35Z</dc:date>
    </item>
  </channel>
</rss>

