<?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: Using token in query where token is evaluated in the query itself in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396761#M115207</link>
    <description>&lt;P&gt;Thank you! This is exactly that I'm looking for! I couldn't figure out how to do it.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jun 2019 08:28:21 GMT</pubDate>
    <dc:creator>denzelchung</dc:creator>
    <dc:date>2019-06-04T08:28:21Z</dc:date>
    <item>
      <title>Using token in query where token is evaluated in the query itself</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396757#M115203</link>
      <description>&lt;P&gt;I have the following query to be performed, where "STRING" is replaced across different queries. Is there a way to replace the STRING with a token and make it such that only 1 query is performed?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="$host$" "STRING" | sort -_time | head 1 | eval time = _time
| eval sender = "STRING" 
| table sender time
...
host="$host$" "STRING2" | sort -_time | head 1 | eval time = _time
| eval sender = "STRING2" 
| table sender time
...
host="$host$" "STRING3" | sort -_time | head 1 | eval time = _time
| eval sender = "STRING3" 
| table sender time
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Simplify to be something like this where $sender$ is set to a dynamic value, but the following doesn't work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;query id="masterQuery"&amp;gt;
    host="$host$" "$sender$" | sort -_time | head 1 | eval time = _time
    | table sender time
&amp;lt;/query&amp;gt;
...
&amp;lt;query base="masterQuery"&amp;gt; | eval sender = "xx" &amp;lt;/query&amp;gt;
&amp;lt;query base="masterQuery"&amp;gt; | eval sender = "yy" &amp;lt;/query&amp;gt; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Jun 2019 02:22:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396757#M115203</guid>
      <dc:creator>denzelchung</dc:creator>
      <dc:date>2019-06-03T02:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using token in query where token is evaluated in the query itself</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396758#M115204</link>
      <description>&lt;P&gt;@denzelchung it would be better if you explain what is the data you have and what is the output required. Seems like you are complicating the use case.&lt;/P&gt;

&lt;P&gt;What is the reason to perform several queries, do you want to have separate visualization for each result? Have you tried &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Viz/VisualizationTrellis"&gt;Trellis Layout&lt;/A&gt; in this case?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 11:43:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396758#M115204</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-06-03T11:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using token in query where token is evaluated in the query itself</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396759#M115205</link>
      <description>&lt;P&gt;Hi @niketnilay, I am trying to evaluate sender to be a fixed string. I have over 10 of these strings and I want 10 different individual visualization.&lt;/P&gt;

&lt;P&gt;I don't think Trellis Layout fits my case as they cannot be split by sourcetype, host, etc. &lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 00:56:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396759#M115205</guid>
      <dc:creator>denzelchung</dc:creator>
      <dc:date>2019-06-04T00:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using token in query where token is evaluated in the query itself</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396760#M115206</link>
      <description>&lt;P&gt;Hi @denzelchung,&lt;/P&gt;

&lt;P&gt;If you want your search to run only once and do further processing you can do with basesearch, where you add dynamic search content in child search rather than in base-search, hence your base search will be executed only once.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;query id="masterQuery"&amp;gt;
     host="$host$" | sort -_time | head 1 | eval time = _time
     | table sender time *
 &amp;lt;/query&amp;gt;
 ...
 &amp;lt;query base="masterQuery"&amp;gt; | search "$sender$"| eval sender = "xx" &amp;lt;/query&amp;gt;
 &amp;lt;query base="masterQuery"&amp;gt; | search "$sender$"| eval sender = "yy" &amp;lt;/query&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;But&lt;/STRONG&gt;, as we are adding search command later most of the time searching all three queries requires less time than this base search as this base-search does not have more search criteria and will return lots of result to process.&lt;/P&gt;

&lt;P&gt;So choose your approach wisely. Hope this helps!!!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 06:36:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396760#M115206</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-04T06:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using token in query where token is evaluated in the query itself</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396761#M115207</link>
      <description>&lt;P&gt;Thank you! This is exactly that I'm looking for! I couldn't figure out how to do it.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 08:28:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-token-in-query-where-token-is-evaluated-in-the-query/m-p/396761#M115207</guid>
      <dc:creator>denzelchung</dc:creator>
      <dc:date>2019-06-04T08:28:21Z</dc:date>
    </item>
  </channel>
</rss>

