<?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 How can I select the index to search dynamically? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-index-to-search-dynamically/m-p/320978#M95884</link>
    <description>&lt;P&gt;I want to say &lt;/P&gt;

&lt;P&gt;| eval my_index=(something, probably using if)&lt;BR /&gt;
  | append [index=(whatever my_index is)]&lt;/P&gt;

&lt;P&gt;How can I do this?  How can I set index= to a field, rather that just a string?&lt;/P&gt;

&lt;P&gt;Further question: Can I make that append completely optional, so if a certain condition isn't met it won't run the subsearch at all (my workaround was going to be setting my_index to something that will never match a real index name)?&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 14:59:13 GMT</pubDate>
    <dc:creator>sillingworth</dc:creator>
    <dc:date>2020-09-29T14:59:13Z</dc:date>
    <item>
      <title>How can I select the index to search dynamically?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-index-to-search-dynamically/m-p/320978#M95884</link>
      <description>&lt;P&gt;I want to say &lt;/P&gt;

&lt;P&gt;| eval my_index=(something, probably using if)&lt;BR /&gt;
  | append [index=(whatever my_index is)]&lt;/P&gt;

&lt;P&gt;How can I do this?  How can I set index= to a field, rather that just a string?&lt;/P&gt;

&lt;P&gt;Further question: Can I make that append completely optional, so if a certain condition isn't met it won't run the subsearch at all (my workaround was going to be setting my_index to something that will never match a real index name)?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:59:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-index-to-search-dynamically/m-p/320978#M95884</guid>
      <dc:creator>sillingworth</dc:creator>
      <dc:date>2020-09-29T14:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the index to search dynamically?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-index-to-search-dynamically/m-p/320979#M95885</link>
      <description>&lt;P&gt;This version replaces the incoming records with the results of the search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval my_index=case(myfield="foo","bar",myfield="fizz","buzz",true(),"AintGotNoIndexByThisName")
| map search="search index=$my_index$ some other search terms and pipes here | table index myfield3 myfield7"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This version does a search once for each value of index and appends it to the current result set...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval my_index=case(myfield="foo","bar",myfield="fizz","buzz",true(),"AintGotNoIndexByThisName")
| appendpipe 
    [ | table index 
      | dedup index
      | map search="search index=$my_index$ some other search terms and pipes here | table index myfield3 myfield7"
    ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As a general case, the only thing that I've found that allows any usage of field values to replace search terms is &lt;CODE&gt;map&lt;/CODE&gt;.  Which is slow and clumsy and should be avoided if possible.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 14:41:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-index-to-search-dynamically/m-p/320979#M95885</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-20T14:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the index to search dynamically?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-index-to-search-dynamically/m-p/320980#M95886</link>
      <description>&lt;P&gt;Ah, I didn't know you could use $something$ for things other that tokens.  Thanks!&lt;/P&gt;

&lt;P&gt;Is there a reason you couldn't just do:&lt;/P&gt;

&lt;P&gt;| eval my_index=(something, probably using if)&lt;BR /&gt;
| append index=$my_index$ .....&lt;/P&gt;

&lt;P&gt;?  I appreciate yours makes it easy to have several indexes.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:59:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-index-to-search-dynamically/m-p/320980#M95886</guid>
      <dc:creator>sillingworth</dc:creator>
      <dc:date>2020-09-29T14:59:23Z</dc:date>
    </item>
  </channel>
</rss>

