<?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: Can you use appendpipe and map together? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256181#M76696</link>
    <description>&lt;P&gt;Someone from Splunk might confirm this,  but on my reading of the docs for append pipe the [ ] constructor is not a subsearch, but a pipeline. Meaning that all the field values are taken from the current result set, and the [ ] cannot contain a subsearch. If you try to run a subsearch in appendpipe, ie &lt;CODE&gt;|appendpipe [[]]&lt;/CODE&gt;, you will get the following parser error&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'SearchParser': Subsearches are only valid as arguments to commands.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Again, the appendpipe [] syntax does not indicate a subsearch, but a different constructor. The map command in your appendpipe probably encounters this parser error but it gets silently dropped. The result of that is of course, NULL. so the result set passed pack up to appendpipe is also NULL, hence why your final result is just count=0, series=splunkd, the same as if you had not had used appendpipe at all.  Interestingly, &lt;CODE&gt;|appendpipe []&lt;/CODE&gt; provides a different result. It takes the values count=0, series=splunkd, does nothing to them , then appends them to your original result, so the final result set is&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;count=0, series=splunkd
count=0, series=splunkd
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Jan 2016 12:32:53 GMT</pubDate>
    <dc:creator>jplumsdaine22</dc:creator>
    <dc:date>2016-01-28T12:32:53Z</dc:date>
    <item>
      <title>Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256178#M76693</link>
      <description>&lt;P&gt;I have a massively complex search that's working.  But now I'd like to augment the output of that search with some additional fields, which can be found by using a secondary search.  For this to be efficient, I need the output of the core search to be fed as parameters of the secondary search.....  (Basically, I'm looking for a "lookup", but a lookup that's based of another search not a CSV file, script, or kv-store.)  I'm really only dealing with one or two results at a time, so the typical inefficiencies of launching multiple searches is not a concern here.&lt;/P&gt;

&lt;P&gt;It seems like this should be possible with the &lt;CODE&gt;appendpipe&lt;/CODE&gt; search command in combination with the &lt;CODE&gt;map&lt;/CODE&gt; command.  Instead of trying to make this work in the context of my already complex search, I broke it down into it's simplest form.&lt;/P&gt;

&lt;P&gt;This search works, demonstrating the the "map" works as-expected:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval series="splunkd" | map search="search index=_internal source=*metrics* group=per_sourcetype_thruput series=$series$ | head 1 | table series kb max_age"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output is:   series=splunkd,kb=10.49353 max_age=1&lt;/P&gt;

&lt;P&gt;This also works, demonstrating that the field "series" makes it from the base search into the subsearch, just as appendpipe advertises:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval series="splunkd" | appendpipe [ eval new_field=series ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output looks like so:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;count=0, series=splunkd&lt;/LI&gt;
&lt;LI&gt;count=0, new_field=splunkd, series=splunkd&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;However, once combined, something goes (silently) wrong:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval series="splunkd" | appendpipe [ map search="search index=_internal source=*metrics* group=per_sourcetype_thruput series=$series$ | head 1 | table kb series max_age" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output looks like:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;count=0, series=splunkd&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;I was expecting the output to look like:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;count=0, series=splunkd&lt;/LI&gt;
&lt;LI&gt;series=splunkd,kb=10.49353 max_age=1&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;In real life, the first result would have lots of other useful fields.  And I'd stick something like &lt;CODE&gt;| stats values(*) as * by series&lt;/CODE&gt; to group all the relevant fields into a single result.&lt;/P&gt;

&lt;P&gt;Any thoughts?  I've been testing this on Splunk 6.2&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;   Here's a slightly better example query and my current workaround.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal source=*metrics* group=per_sourcetype_thruput
| stats sum(ev) as ev by series
| sort 1 - ev
| appendpipe [ map search="search index=_internal source=*metrics* group=per_sourcetype_thruput series=$series$ | head 1 | table series kb" ]
| selfjoin series
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The work around doesn't use &lt;CODE&gt;map&lt;/CODE&gt;, because without &lt;CODE&gt;appendpipe&lt;/CODE&gt; there's no way to "pass in" fields.  So instead we have to use a subsearch, which essentially requires repeating the entire base search, which works but isn't very efficient.  Here's the search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal source=*metrics* group=per_sourcetype_thruput
| stats sum(ev) as ev by series
| sort 1 - ev
| append [
  search index=_internal source=*metrics* group=per_sourcetype_thruput [
    search index=_internal source=*metrics* group=per_sourcetype_thruput
    | stats sum(ev) as ev by series
    | sort 1 - ev
    | return series ]
  |  head 1
  | table series kb ]
| selfjoin series
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;Update 2:&lt;/STRONG&gt;  For whatever it's worth, the problem with the &lt;CODE&gt;map&lt;/CODE&gt; is not field substitution, because this does not work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | appendpipe [ map search="search index=_internal source=*metrics* group=per_sourcetype_thruput series=splunkd | head 1 | table series kb" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Weird.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 23:10:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256178#M76693</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2016-01-27T23:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256179#M76694</link>
      <description>&lt;P&gt;Seriously, I was amazed why the appendpipe did not work. still puzzled. Meanwhile, I don't know how feasible it will be with your complex search, something like this can generate the output that you seek. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval series="splunkd" | append [ | stats count | eval series="splunkd" | map search="search index=_internal source=*metrics* group=per_sourcetype_thruput series=$series$ | head 1 | table kb series max_age" ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2016 04:02:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256179#M76694</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-01-28T04:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256180#M76695</link>
      <description>&lt;P&gt;Also, I just saw the 2nd comment at the bottom of this page and it says the map inside subsearch doesn't support values substitution (from base search). &lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchReference/Map"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchReference/Map&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 04:07:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256180#M76695</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-01-28T04:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256181#M76696</link>
      <description>&lt;P&gt;Someone from Splunk might confirm this,  but on my reading of the docs for append pipe the [ ] constructor is not a subsearch, but a pipeline. Meaning that all the field values are taken from the current result set, and the [ ] cannot contain a subsearch. If you try to run a subsearch in appendpipe, ie &lt;CODE&gt;|appendpipe [[]]&lt;/CODE&gt;, you will get the following parser error&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'SearchParser': Subsearches are only valid as arguments to commands.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Again, the appendpipe [] syntax does not indicate a subsearch, but a different constructor. The map command in your appendpipe probably encounters this parser error but it gets silently dropped. The result of that is of course, NULL. so the result set passed pack up to appendpipe is also NULL, hence why your final result is just count=0, series=splunkd, the same as if you had not had used appendpipe at all.  Interestingly, &lt;CODE&gt;|appendpipe []&lt;/CODE&gt; provides a different result. It takes the values count=0, series=splunkd, does nothing to them , then appends them to your original result, so the final result set is&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;count=0, series=splunkd
count=0, series=splunkd
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2016 12:32:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256181#M76696</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-01-28T12:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256182#M76697</link>
      <description>&lt;P&gt;updated for clarity&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 12:43:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256182#M76697</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-01-28T12:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256183#M76698</link>
      <description>&lt;P&gt;So it's interesting to me that the &lt;CODE&gt;map&lt;/CODE&gt; works properly from an &lt;CODE&gt;append&lt;/CODE&gt; but not from &lt;CODE&gt;appendpipe&lt;/CODE&gt;.  (This may lend itself to jplumsdaine22 note about subsearch vs pipeline)&lt;/P&gt;

&lt;P&gt;And yeah, my current workaround is using a bunch of appends and subsearches to get what I need.  The key difference here is that the value of "series" isn't know ahead of time, it's determined by an earlier search, so setting the value within the append sub-search isn't really an option for me.&lt;/P&gt;

&lt;P&gt;So my search ends up looking like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;base search returning a,b&amp;gt; | append [ sourcetype=c [ &amp;lt;base search returning b&amp;gt; | return b ] | manipulate ... | table c ] | stats values(*) as * by b | table a b c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And of course this simplification ignores the fact that if the base search returns nothing, the parent search essentially goes wide open and returns too many results, leading the awkward solution like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;base search returning a,b&amp;gt; | append [ sourcetype=c [ &amp;lt;base search returning b&amp;gt; | append [ stats count | eval b="NeverOccuringInRealLife" | fields b ] | return 2 b ] | manipulate ... | table c ] | stats values(*) as * by b
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;May need to switch over to handling all this logic externally and use some REST APIs; which is just a bit frustrating because SPL is so close to being able to handle this natively.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 15:28:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256183#M76698</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2016-01-28T15:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256184#M76699</link>
      <description>&lt;P&gt;Hmm, it looks like a simple &lt;CODE&gt;| append [[]]&lt;/CODE&gt; give the same error, which I suspect is simply because it's nonsensical.  In particular, there's no generating SPL command given.  So a search like &lt;CODE&gt;| appendpipe [ search [ search ] ]&lt;/CODE&gt; does "work", but doesn't do anything useful.&lt;/P&gt;

&lt;P&gt;I agree that there's a subtle difference between the way that a subsearch works and the way the pipeline works.  So with the example of &lt;CODE&gt;| appendpipe [ (#1) search [ (#2) search ] ]&lt;/CODE&gt;, with search #1, that is a post-filtering operation, where as search #2 is a generating command.  But I think you still have to have &lt;EM&gt;some&lt;/EM&gt; SPL command in #1, because a subsearch can only be used within certain commands, like &lt;CODE&gt;search&lt;/CODE&gt;, &lt;CODE&gt;append&lt;/CODE&gt;, &lt;CODE&gt;join&lt;/CODE&gt;, and so on.&lt;/P&gt;

&lt;P&gt;But I'm still not sure why this would limit the use of the &lt;CODE&gt;map&lt;/CODE&gt; command from within the context of an &lt;CODE&gt;appendpipeline&lt;/CODE&gt; subsearch/subpipeline.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 18:11:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256184#M76699</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2016-01-28T18:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256185#M76700</link>
      <description>&lt;P&gt;Derp yep you're right [ [] ] does nothing anyway.&lt;/P&gt;

&lt;P&gt;Here's a run everywhere example of a subsearch running just fine in appendpipe&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_audit | head 1 | stats count | eval series="splunkd" | appendpipe [ search index=_audit [ search index=_internal | head 50 | fields host ] | stats count by host | rename host as series ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I am incorrect in saying that a subsearch won't function in an appendpipe. So ignore that bit. &lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 12:59:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256185#M76700</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-01-29T12:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256186#M76701</link>
      <description>&lt;P&gt;Ignore my earlier answer. It is incorrect (maybe someone can downvote it?) The answer is yes you can use it, but it seems to run only once, and I can't figure out how to pass values to it. &lt;BR /&gt;
Here's a wacky run anywhere&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_audit | head 10  | stats count by host  | appendpipe [  map search="search  | head 5 | fields _raw host"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That should run map 50 times, but looks like it just runs the once,&lt;/P&gt;

&lt;P&gt;Maybe one of the Splunk developers can explain?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 14:05:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256186#M76701</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2016-01-29T14:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256187#M76702</link>
      <description>&lt;P&gt;Did anyone ever explain this properly? Might be one for the slack channel&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 23:58:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256187#M76702</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-03-10T23:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use appendpipe and map together?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256188#M76703</link>
      <description>&lt;P&gt;From what I read and suspect...&lt;/P&gt;

&lt;P&gt;The "appendpipe" command looks to simply run a given command totally outside the realm of whatever other searches are going on...and append those results to the answerset.&lt;/P&gt;

&lt;P&gt;Thus, in your example, the map command inside the appendpipe would be ignorant of the data in the other (preceding/outside) part of the search. As such, indeed, it would only run one time.&lt;/P&gt;

&lt;P&gt;There are a LOT of people seeking ways to do some similar things (including me...as I want to do a sub-search based on data from elsewhere) and it's not easily intuitive to do so.... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 00:02:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-appendpipe-and-map-together/m-p/256188#M76703</guid>
      <dc:creator>rstitt</dc:creator>
      <dc:date>2018-01-16T00:02:09Z</dc:date>
    </item>
  </channel>
</rss>

