<?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: Subsearch - Add a column in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343615#M39068</link>
    <description>&lt;P&gt;@somesoni2 - what do you think about something like this as a way of getting around the possibility of the second search returning too much data? &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 sourcetype=b | stats sum(price) as total by product, region
 | appendpipe 
     [ | stats by product | format | rename search as myproductlist 
       | map search="search index=2 sourcetype=c $myproductlist$ | stats values(tags) as tags by product" ]
 | stats values(region) as region, values(total) as total, values(tags) as "total tags" by product
 | where isnotnull(region)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 31 Jul 2017 18:28:18 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-07-31T18:28:18Z</dc:date>
    <item>
      <title>Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343613#M39066</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;

&lt;P&gt;How can I get an additional column in the output by matching on a common field. Lets say, below query gives me:&lt;BR /&gt;
index=1 sourcetype=b | stats sum(price) as total by products, region&lt;/P&gt;

&lt;P&gt;products region total&lt;BR /&gt;
a               v           111&lt;BR /&gt;
b              w           222&lt;BR /&gt;
c               x           333&lt;BR /&gt;
d               y           444&lt;BR /&gt;
e               z           555&lt;/P&gt;

&lt;P&gt;Now, I have another source that may have tags for each product and there can be multiple tags associated to a single products. The second source has different list and count, i.e, it may have more number of products. So, how can I get something like below for the matching ones for column products from above query:&lt;BR /&gt;
products region total tags&lt;BR /&gt;
a               v           111  qw,as&lt;BR /&gt;
b              w           222  we&lt;BR /&gt;
c               x           333&lt;BR /&gt;
d               y           444  sd,zx,xc&lt;BR /&gt;
e               z           555&lt;/P&gt;

&lt;P&gt;Can I get some help with the query please.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2017 16:47:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343613#M39066</guid>
      <dc:creator>Vikas_Sharma</dc:creator>
      <dc:date>2017-07-31T16:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343614#M39067</link>
      <description>&lt;P&gt;Give this a try (will work fine unless the subsearch has too many rows to produce and/or takes lots of time to run)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 sourcetype=b | stats sum(price) as total by products, region
| append [search index=2 sourcetype=c | stats values(tags) as tags by product]
| stats values(region) as region, values(total) as total values(tags) as "total tags" by product
| where isnotnull(region)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2017 17:07:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343614#M39067</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-31T17:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343615#M39068</link>
      <description>&lt;P&gt;@somesoni2 - what do you think about something like this as a way of getting around the possibility of the second search returning too much data? &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 sourcetype=b | stats sum(price) as total by product, region
 | appendpipe 
     [ | stats by product | format | rename search as myproductlist 
       | map search="search index=2 sourcetype=c $myproductlist$ | stats values(tags) as tags by product" ]
 | stats values(region) as region, values(total) as total, values(tags) as "total tags" by product
 | where isnotnull(region)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2017 18:28:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343615#M39068</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-31T18:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343616#M39069</link>
      <description>&lt;P&gt;Map command in a subsearch can be brutal (there are good chances that it'll get auto-finalized after 2 mins if there are many products).  I would rather use an eventstats implementation for that (to avoid subsearches completely) like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( index=1 sourcetype=b) OR (index=2 sourcetype=c) 
| eventstats values(tags) as tags_all by product
| eval tags=coalesce(tags,tags_all)
| search  index=1 sourcetype=b
| stats sum(price) as total values(tags) as "total tags" by product region
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2017 18:56:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343616#M39069</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-31T18:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343617#M39070</link>
      <description>&lt;P&gt;Thank you for your responses @somesoni2 and @DalJeanis. &lt;/P&gt;

&lt;P&gt;I may have multiple product values in my second source which again can have 0 or more tags. I think it will make more sense if I add some data for the second source here.  &lt;/P&gt;

&lt;P&gt;index=2 sourcetype=c | stats values(tags) as tags by product&lt;/P&gt;

&lt;P&gt;product tags&lt;BR /&gt;
a,f           qw,as&lt;BR /&gt;
b             we&lt;BR /&gt;
c,g,h&lt;BR /&gt;&lt;BR /&gt;
d             sd,zx,xc&lt;BR /&gt;
e              &lt;/P&gt;

&lt;P&gt;So, the product 'a' gets tags 'qw,as' in the final output. &lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2017 18:57:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343617#M39070</guid>
      <dc:creator>Vikas_Sharma</dc:creator>
      <dc:date>2017-07-31T18:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343618#M39071</link>
      <description>&lt;P&gt;Did you get a chance to try any of the answers?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2017 19:28:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343618#M39071</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-31T19:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343619#M39072</link>
      <description>&lt;P&gt;There is a problem.&lt;BR /&gt;
The products column from source1 is single valued but the productlist column in source2 is multivalued.&lt;/P&gt;

&lt;P&gt;index=1 sourcetype=b | stats sum(price) as total by products, region&lt;/P&gt;

&lt;P&gt;products    region      total&lt;BR /&gt;
a       v       111&lt;BR /&gt;
b       w       222&lt;BR /&gt;
c       x       333&lt;BR /&gt;
d       y       444&lt;BR /&gt;
e       z       555&lt;/P&gt;

&lt;P&gt;index=2 sourcetype=c | stats values(tags) as tags by productlist&lt;/P&gt;

&lt;P&gt;productlist tags&lt;BR /&gt;
a,f     qw,as&lt;BR /&gt;
b       we&lt;BR /&gt;
c,g,h&lt;BR /&gt;&lt;BR /&gt;
d       sd,zx,xc&lt;BR /&gt;
e&lt;/P&gt;

&lt;P&gt;Output:&lt;BR /&gt;
products    region      total       tags&lt;BR /&gt;
a       v       111     qw,as&lt;BR /&gt;
b       w       222     we&lt;BR /&gt;
c       x       333&lt;BR /&gt;&lt;BR /&gt;
d       y       444     sd,zx,xc&lt;BR /&gt;
e       z       555&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2017 20:37:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343619#M39072</guid>
      <dc:creator>Vikas_Sharma</dc:creator>
      <dc:date>2017-07-31T20:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343620#M39073</link>
      <description>&lt;P&gt;I guess the problem is not productlist being multivalued field (the stats should've made it single valued), but the different column names in two sources. Try these&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=1 sourcetype=b | stats sum(price) as total by products, region
 | append [search index=2 sourcetype=c | stats values(tags) as tags by productlist | rename productlist as product]
 | stats values(region) as region, values(total) as total values(tags) as "total tags" by product
 | where isnotnull(region)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;AND &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( index=1 sourcetype=b) OR (index=2 sourcetype=c) 
| eval product=coalesce(product,productlist)
 | eventstats values(tags) as tags_all by product
 | eval tags=coalesce(tags,tags_all)
 | search  index=1 sourcetype=b
 | stats sum(price) as total values(tags) as "total tags" by product region
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2017 20:43:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343620#M39073</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-31T20:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343621#M39074</link>
      <description>&lt;P&gt;Umm, I still think its the problem with the multivalue. All of these queries return data for only those rows which have single values in productlist. &lt;/P&gt;

&lt;P&gt;We are renaming productlist as product but 'productlist' may not always have the same matching column values as that in 'product'. &lt;/P&gt;

&lt;P&gt;product &lt;BR /&gt;
a&lt;BR /&gt;
b&lt;BR /&gt;
c&lt;BR /&gt;
d&lt;BR /&gt;
e&lt;/P&gt;

&lt;P&gt;productlist&lt;BR /&gt;
a,f&lt;BR /&gt;
b&lt;BR /&gt;
c,g,h&lt;BR /&gt;
d&lt;BR /&gt;
e&lt;/P&gt;

&lt;P&gt;For the examples that I have provided, the output is going to be like below and there is not going to be any tags for product 'a':&lt;/P&gt;

&lt;P&gt;products region total tags&lt;BR /&gt;
a v 111&lt;BR /&gt;
b w 222 we&lt;BR /&gt;
c x 333&lt;BR /&gt;
d y 444 sd,zx,xc&lt;BR /&gt;
e z 555&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2017 21:51:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343621#M39074</guid>
      <dc:creator>Vikas_Sharma</dc:creator>
      <dc:date>2017-07-31T21:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch - Add a column</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343622#M39075</link>
      <description>&lt;P&gt;subsearch query:&lt;BR /&gt;
append [ search index=2 sourcetype=c | eval temp=split(productlist,",") | mvexpand temp | stats values(tags) as tags by temp | rename temp as product ]&lt;/P&gt;

&lt;P&gt;Thank you @somesoni2 and @DalJeanis for helping with this.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 17:52:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Subsearch-Add-a-column/m-p/343622#M39075</guid>
      <dc:creator>Vikas_Sharma</dc:creator>
      <dc:date>2017-08-01T17:52:37Z</dc:date>
    </item>
  </channel>
</rss>

