<?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: How do you prevent the map command from encapsulating the variable in quotes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435109#M124097</link>
    <description>&lt;P&gt;I feel your pain.  I had the same experience.  I absolutely &lt;EM&gt;had&lt;/EM&gt; to make it work.  It took me weeks and then God pushed the idea into my head; it just clicked!  I solved it in my mind and I knew that it would work before I even tested it.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Jan 2019 16:44:23 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-01-29T16:44:23Z</dc:date>
    <item>
      <title>How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435102#M124090</link>
      <description>&lt;P&gt;The quotes can &lt;EM&gt;only&lt;/EM&gt; be seen in the &lt;CODE&gt;search.log&lt;/CODE&gt; in one of the &lt;CODE&gt;SearchParser&lt;/CODE&gt; component events. &lt;/P&gt;

&lt;P&gt;My ultimate goal is to be able to pass a single field with an arbitrary number of values through map to the same variable in multiple sections of the subsearch, one of which is specifically in the &lt;CODE&gt;by&lt;/CODE&gt; section of a &lt;CODE&gt;tstats&lt;/CODE&gt;. The examples below are proofs-of-concept to illustrate the problem. I've tried other approaches including tokens, not that there's a token to remove quotes, but have obviously been unsuccessful in my various attempts. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Ex #1&lt;/STRONG&gt;: Value End Up Quoted &amp;amp; Does Not Work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;pre&amp;gt;| makeresults
| eval test = "sourcetype,host"
| map search="| tstats latest(_time) AS lastTime WHERE index=_internal by $test$"&amp;lt;/pre&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Ex #2&lt;/STRONG&gt;: Does Not Quote Value &amp;amp; Works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;pre&amp;gt;| makeresult
| eval test = "sourcetype"
| map search="| tstats latest(_time) AS lastTime WHERE index=_internal by $test$"&amp;lt;/pre&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's an alternative approach I tested, but it only seems to execute whatever is in the first record of the nested subsearch, which in this case is "sourcetype,host".&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Ex #3&lt;/STRONG&gt;: "by" Subsearch&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;pre&amp;gt;| makeresults 
| fields sourcetype, host, lastTime 
| map 
    [| tstats latest(_time) AS lastTime WHERE index=_internal by 
        [| makeresults count=2 
        | streamstats count AS counter 
        | eval search = if(counter=1, "sourcetype,host", "sourcetype") 
        | fields - _time, counter ] 
        ]&amp;lt;/pre&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: I did see the post "&lt;EM&gt;Why is there a problem when passing a command through a variable in map-command?&lt;/EM&gt;", but it doesn't really help in this situation seeing as it doesn't solve how to do it in the &lt;CODE&gt;by&lt;/CODE&gt; section. At least, if it does, I missed it.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 17:09:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435102#M124090</guid>
      <dc:creator>quasikaze</dc:creator>
      <dc:date>2019-01-28T17:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435103#M124091</link>
      <description>&lt;P&gt;Did you try using &lt;BR /&gt;
    \"$test$\" instead of $test$ in your second example?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 17:24:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435103#M124091</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-01-28T17:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435104#M124092</link>
      <description>&lt;P&gt;Yeah. No luck there. Thanks though!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 18:58:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435104#M124092</guid>
      <dc:creator>quasikaze</dc:creator>
      <dc:date>2019-01-28T18:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435105#M124093</link>
      <description>&lt;P&gt;This is a difficult problem that took me forever to figure out but once I show you the trick, you are going to kick yourself.  You cannot stop &lt;CODE&gt;map&lt;/CODE&gt; from doing this, but you can work around it; you need to use both a &lt;CODE&gt;subsearch&lt;/CODE&gt; and a &lt;CODE&gt;map&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval test = "sourcetype,host"
| map search="| tstats latest(_time) AS lastTime WHERE index=_internal by [|makeresults | eval test=$test$ | return $test]"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;BOOM!  (That is the sound of the microphone that I dropped hitting my foot).&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 22:50:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435105#M124093</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-28T22:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435106#M124094</link>
      <description>&lt;P&gt;You took my suggestion to &lt;CODE&gt;just add a subsearch&lt;/CODE&gt; but missed it by &lt;CODE&gt;&amp;gt;that&amp;lt;&lt;/CODE&gt; much!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 22:58:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435106#M124094</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-28T22:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435107#M124095</link>
      <description>&lt;P&gt;This is what I needed! Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 15:48:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435107#M124095</guid>
      <dc:creator>quasikaze</dc:creator>
      <dc:date>2019-01-29T15:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435108#M124096</link>
      <description>&lt;P&gt;lol! That's actually what I tried a couple days earlier when talking back and forth with daljeanis. When I saw your comment about that, I had already forgotten about it and had no idea where you were talking about adding a subsearch or what to even put in it and just confusingly dismissed it. :facepalm: There's absolutely no way I would've solved it without your help! I've never had reason to use &lt;CODE&gt;return&lt;/CODE&gt;, so I completely forgot it even existed! I've been working this issue off and on for months, so to finally have a solution is inspiring. Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 16:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435108#M124096</guid>
      <dc:creator>quasikaze</dc:creator>
      <dc:date>2019-01-29T16:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435109#M124097</link>
      <description>&lt;P&gt;I feel your pain.  I had the same experience.  I absolutely &lt;EM&gt;had&lt;/EM&gt; to make it work.  It took me weeks and then God pushed the idea into my head; it just clicked!  I solved it in my mind and I knew that it would work before I even tested it.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 16:44:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435109#M124097</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-29T16:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435110#M124098</link>
      <description>&lt;P&gt;Tokens, tokens, everywhere!  I shudder to think of how this will look as a dashboard panel!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 00:53:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/435110#M124098</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-30T00:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do you prevent the map command from encapsulating the variable in quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/639033#M221424</link>
      <description>&lt;P&gt;Thank you so much&lt;BR /&gt;&lt;BR /&gt;I didn't undestand the tricks with `return $test` and why only one $&lt;BR /&gt;&lt;BR /&gt;But this make the job!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2023 15:10:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-prevent-the-map-command-from-encapsulating-the/m-p/639033#M221424</guid>
      <dc:creator>pierrealex</dc:creator>
      <dc:date>2023-04-06T15:10:08Z</dc:date>
    </item>
  </channel>
</rss>

