<?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: Query changes dynamically with selected index names? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158068#M185833</link>
    <description>&lt;P&gt;Right, I think the query I posted should do just that though. What exactly is not working? Could you use the job inspector to see where it's failing?&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2015 15:06:06 GMT</pubDate>
    <dc:creator>masonmorales</dc:creator>
    <dc:date>2015-04-29T15:06:06Z</dc:date>
    <item>
      <title>Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158054#M185819</link>
      <description>&lt;P&gt;I am trying to fetch the project names from different logs which has different field name and it is depend on index names, and not able to find out correct way to do it.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;index1 =xyz and project=proj_n&lt;/LI&gt;
&lt;LI&gt;index2=yzx and project=project_n&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;&lt;STRONG&gt;index=xyz sourcetype=aaa | eval project_names=if(index="xyz","proj_n="&lt;/STRONG&gt;&lt;STRONG&gt;"","project_n="&lt;/STRONG&gt;&lt;STRONG&gt;"") | chart count(host) as hostnames by project_names&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I used above query but not getting correct output.&lt;/P&gt;

&lt;P&gt;Required Output: &lt;BR /&gt;
project_names&lt;BR /&gt;
abc1&lt;BR /&gt;
bcd2&lt;BR /&gt;
cde3&lt;BR /&gt;
efg4&lt;BR /&gt;
....&lt;BR /&gt;
....&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:37:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158054#M185819</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2020-09-28T19:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158055#M185820</link>
      <description>&lt;P&gt;hi&lt;BR /&gt;
try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;

  &amp;lt;label&amp;gt;Dropdown Form Input Element&amp;lt;/label&amp;gt;

  &amp;lt;description&amp;gt;Events Filtered by index using Dropdown Form Inputs&amp;lt;/description&amp;gt;

  &amp;lt;fieldset autoRun="true" submitButton="false"&amp;gt;
    &amp;lt;input type="dropdown" token="index" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select a index:&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;choice value="*"&amp;gt;All&amp;lt;/choice&amp;gt;
      &amp;lt;populatingSearch fieldForValue="index" fieldForLabel="index" earliest="0" latest="now"&amp;gt;
        &amp;lt;![CDATA[index=* OR index=_* | stats count by index]]&amp;gt;
      &amp;lt;/populatingSearch&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;

  &amp;lt;row&amp;gt;
    &amp;lt;chart&amp;gt;
      &amp;lt;title&amp;gt;Chart of Events for index="$index$" &amp;lt;/title&amp;gt;
      &amp;lt;searchString&amp;gt;index=$index$ OR index=_$index$  | chart count(host) as hostnames by project_names&amp;lt;/searchString&amp;gt;
      &amp;lt;earliestTime&amp;gt;0&amp;lt;/earliestTime&amp;gt;
      &amp;lt;latestTime&amp;gt;now&amp;lt;/latestTime&amp;gt;
      &amp;lt;option name="charting.chart"&amp;gt;column&amp;lt;/option&amp;gt;
    &amp;lt;/chart&amp;gt;
  &amp;lt;/row&amp;gt;

&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Apr 2015 15:07:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158055#M185820</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2015-04-27T15:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158056#M185821</link>
      <description>&lt;P&gt;Thansk Gys,&lt;BR /&gt;
I tried using your query but no output.&lt;/P&gt;

&lt;P&gt;Let me tell you few things &lt;BR /&gt;
We have project names with different fields names in different index. Suppose if I select index1 (abc) i want project names (fieldname of project names is "proj_n") from index1 list and if I select index2 (xyz) I want project names (fieldname of project name is "proj_names") from index2 list.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:38:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158056#M185821</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2020-09-28T19:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158057#M185822</link>
      <description>&lt;P&gt;HI try this:&lt;BR /&gt;
1.this is for all project names in the two index.&lt;/P&gt;

&lt;P&gt;index=xyz OR index=yxz  sourcetype=aaa ..... |eval project_name=coalesce(proj_n,project_n)|&lt;BR /&gt;
 chart count(host) as hostnames by project_name&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Now if you want it for a chosen index,assuming that you are doing it in a dashboard:&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;a-create a dropdown, populate it with your different Indexes.&lt;/P&gt;

&lt;P&gt;b-the query will look like this:&lt;/P&gt;

&lt;P&gt;index=$index_token$ source=..... OR sourcetype=.......|eval project_name=if( "$index_token$"=xyz, "project_n","proj_n")|&lt;BR /&gt;
 chart count(host) as hostnames by project_name&lt;/P&gt;

&lt;P&gt;NOTE: you can have nested if(...) if you have more than 2 index or you can use case(...)&lt;/P&gt;

&lt;P&gt;hope this will help....&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:38:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158057#M185822</guid>
      <dc:creator>stephane_cyrill</dc:creator>
      <dc:date>2020-09-28T19:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158058#M185823</link>
      <description>&lt;P&gt;Hi ilyazs &lt;BR /&gt;
Look at this xml code , it will be help you well , just try it.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;form&amp;gt;
    &amp;lt;label&amp;gt;Dropdown Form Input Element&amp;lt;/label&amp;gt;
    &amp;lt;description&amp;gt;display results by index&amp;lt;/description&amp;gt;
     &amp;lt;fieldset autoRun="true" submitButton="false"&amp;gt;
    &amp;lt;input type="dropdown" token="index_tok" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Select an index:&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;*&amp;lt;/default&amp;gt;
      &amp;lt;choice value="*"&amp;gt;All&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="xyz"&amp;gt;xyz&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="yzx"&amp;gt;yzx&amp;lt;/choice&amp;gt;
    &amp;lt;/input&amp;gt;
     &amp;lt;/fieldset&amp;gt;
    &amp;lt;row&amp;gt;
    &amp;lt;chart&amp;gt;
    &amp;lt;title&amp;gt;Chart of Events for index="$index_tok$" &amp;lt;/title&amp;gt;
    &amp;lt;searchString&amp;gt;index=$index_tok$ sourcetype=aaa | eval project_names=if($index_tok$=="xyz","proj_n=""","project_n=""") | chart count(host) as hostnames by project_names&amp;lt;/searchString&amp;gt;
    &amp;lt;earliestTime&amp;gt;0&amp;lt;/earliestTime&amp;gt;
    &amp;lt;latestTime&amp;gt;now&amp;lt;/latestTime&amp;gt;
    &amp;lt;option name="charting.chart"&amp;gt;column&amp;lt;/option&amp;gt;
    &amp;lt;/chart&amp;gt;
    &amp;lt;/row&amp;gt;
    &amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Apr 2015 22:27:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158058#M185823</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2015-04-27T22:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158059#M185824</link>
      <description>&lt;P&gt;Assuming it's just two indexes, you could simply do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=xyz OR index=yzx 
| rename proj_n as project_names
| eval project_names=if(isnull(project_names), project_n, project_names) 
| table project_names
| dedup project_names
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Apr 2015 04:12:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158059#M185824</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-04-28T04:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158060#M185825</link>
      <description>&lt;P&gt;Hi Stephane,&lt;BR /&gt;
Thanks for your reply, this is not working&lt;BR /&gt;
I want list of project names available in given timeperiod. I have to try by project_n=&lt;EM&gt;(star) or proj_n=&lt;/EM&gt;(star) (project_n=star or asterisk)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:38:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158060#M185825</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2020-09-28T19:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158061#M185826</link>
      <description>&lt;P&gt;Hi Chimell,&lt;BR /&gt;
Thanks for your reply, this is not working&lt;BR /&gt;
I want list of project names available in given timeperiod. I have to try by project_n=&lt;EM&gt;(star) or proj_n=&lt;/EM&gt;(star) (project_n=star or asterisk)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:38:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158061#M185826</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2020-09-28T19:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158062#M185827</link>
      <description>&lt;P&gt;Hi Mason,&lt;BR /&gt;
Thanks for your reply, this is not working&lt;BR /&gt;
I want list of project names available in given timeperiod. I have to try by project_n=&lt;EM&gt;(star) or proj_n=&lt;/EM&gt;(star) (project_n=star or asterisk)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:38:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158062#M185827</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2020-09-28T19:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158063#M185828</link>
      <description>&lt;P&gt;I tried using above query to fetch list of project_names from different index_names, project names has different field names for each index.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;index=$index_name$ sourcetype=$source_type$ host=$host_name$ | eval Project_N=if($index_name$=="xyz", "project_n= * "&lt;/STRONG&gt;, &lt;STRONG&gt;"proj_n= * ") | chart count(host) as hostname by Project_N&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I tried using cases, if statement and coalesce function but not getting list of project names.&lt;/P&gt;

&lt;P&gt;2 Logfiles for your undestanding -&lt;/P&gt;

&lt;P&gt;Below are the two log files-&lt;BR /&gt;
LogFile1&lt;BR /&gt;
index,sourcetype,host,proj_n,entry_post&lt;BR /&gt;
abc,aaa,10.11.190.12,xyz,text....&lt;BR /&gt;
abc,aaa,10.11.190.12,xxx,text....&lt;BR /&gt;
abc,aaa,10.11.190.12,yzx,text....&lt;/P&gt;

&lt;P&gt;LogFile-2&lt;BR /&gt;
index,sourcetype,host,project_n,entry_post&lt;BR /&gt;
bbc,aaa,10.11.190.12,yyy,text.... &lt;BR /&gt;
bbc,aaa,10.11.190.12,zzz,text....&lt;BR /&gt;
bbc,aaa,10.11.190.12,bbb,text....&lt;/P&gt;

&lt;P&gt;Suppose if I have index=abc, output list should be project_name=xyz, xxx, yzx, ....&lt;BR /&gt;
if index=bbc, then output list should be project_name=yyy, zzz, bbb, .....&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:38:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158063#M185828</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2020-09-28T19:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158064#M185829</link>
      <description>&lt;P&gt;Can you provide a sample data,I'm sure with that we can understand you better .....&lt;/P&gt;

&lt;P&gt;You up there that you need project names for a given period. If the request was working then just add a time picker and tokenize it.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2015 09:27:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158064#M185829</guid>
      <dc:creator>stephane_cyrill</dc:creator>
      <dc:date>2015-04-28T09:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158065#M185830</link>
      <description>&lt;P&gt;Below are the two log files-&lt;BR /&gt;
LogFile1&lt;BR /&gt;
index,sourcetype,host,proj_n,entry_post&lt;BR /&gt;
abc,aaa,10.11.190.12,xyz,text....&lt;BR /&gt;
abc,aaa,10.11.190.12,xxx,text....&lt;BR /&gt;
abc,aaa,10.11.190.12,yzx,text....   &lt;/P&gt;

&lt;P&gt;LogFile-2&lt;BR /&gt;
index,sourcetype,host,project_n,entry_post&lt;BR /&gt;
bbc,aaa,10.11.190.12,yyy,text....&lt;BR /&gt;&lt;BR /&gt;
bbc,aaa,10.11.190.12,zzz,text....&lt;BR /&gt;
bbc,aaa,10.11.190.12,bbb,text....&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:38:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158065#M185830</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2020-09-28T19:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158066#M185831</link>
      <description>&lt;P&gt;I can see that your data are from 2 different log files not from 2 different indexes. So i guest what you want is: project names from both log files for a given index and for a given period.&lt;/P&gt;

&lt;P&gt;1- the query :&lt;/P&gt;

&lt;P&gt;source=LogFile1 OR source=LogFile-2 index=$index_token$ |eval projetN=coalesce(proj_n,project_n)|eval project_name=case("$index_token$"="abc","proj_n","$index_token$"="bbc","project_n","$index_token$"="*","projetN")|&lt;BR /&gt;
chart count(host) as hostnames by project_name&lt;/P&gt;

&lt;P&gt;2-to control the time periode,create a time picker. if your using splunk 6.2, put the above search in the tag QUERY and under this put $time.earliest$ and $time.latest$ in the tag EARLIEST and LATEST.&lt;/P&gt;

&lt;P&gt;3-so finally you will have an input for index, an input for time picker. if you set them very well it will be ok for you.&lt;/P&gt;

&lt;P&gt;good luck......&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:42:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158066#M185831</guid>
      <dc:creator>stephane_cyrill</dc:creator>
      <dc:date>2020-09-28T19:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158067#M185832</link>
      <description>&lt;P&gt;Output of above query is count of project names, but i want list of names of project_name.&lt;/P&gt;

&lt;P&gt;Suppose if I have &lt;STRONG&gt;index=abc&lt;/STRONG&gt;, output list should be &lt;STRONG&gt;project_name=xyz, xxx, yzx, ....&lt;/STRONG&gt;&lt;BR /&gt;
if &lt;STRONG&gt;index=bbc&lt;/STRONG&gt;, then output list should be &lt;STRONG&gt;project_name=yyy, zzz, bbb, .....&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2015 10:49:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158067#M185832</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2015-04-29T10:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158068#M185833</link>
      <description>&lt;P&gt;Right, I think the query I posted should do just that though. What exactly is not working? Could you use the job inspector to see where it's failing?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2015 15:06:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158068#M185833</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-04-29T15:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Query changes dynamically with selected index names?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158069#M185834</link>
      <description>&lt;P&gt;Thanks.&lt;BR /&gt;
I got the list of project_names&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2015 15:24:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-changes-dynamically-with-selected-index-names/m-p/158069#M185834</guid>
      <dc:creator>ilyazs</dc:creator>
      <dc:date>2015-04-29T15:24:21Z</dc:date>
    </item>
  </channel>
</rss>

