<?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 Subsearch for multiple sourcetypes and fieldnames in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298103#M89892</link>
    <description>&lt;P&gt;I need to do a search in two different sourcetypes and use the result to do additional searches in these queries.&lt;BR /&gt;
But I have the problem that, while both sourcetypes have similar values, they use different prefixes. So in sourcetype=A the ip is called aIP and in sourcetype=B the ip is called bIP respectively.&lt;/P&gt;

&lt;P&gt;So you could search with&lt;BR /&gt;
aIP=”192.168.0.1” OR bIp=”192.168.0.1”&lt;/P&gt;

&lt;P&gt;However if you want to use these ips from a subsearch of both of these tables it becomes problematic and I am not sure what the best solution is.&lt;BR /&gt;
So let’s assume I want to find the IPs used on a specific page called “MAINPAGE”. And use these IPs to search for other pages visited by them on both sources.&lt;BR /&gt;
I tried to minimize the code as far as possible. It might not make any sense anymore, but I hope it’s enough to bring across my point.&lt;/P&gt;

&lt;P&gt;Index=web (sourcetype=a OR sourcetype=b)&lt;BR /&gt;
[search index=web sourcetype=a apage=MAINPAGE | table aIP]&lt;/P&gt;

&lt;P&gt;OR&lt;BR /&gt;
[search index=web sourcetype=a apage=MAINPAGE | rename aIP as bIP | table bIP]&lt;BR /&gt;
OR&lt;BR /&gt;
[search index=web sourcetype=b bpage=MAINPAGE | table bIP]&lt;BR /&gt;
OR&lt;BR /&gt;
[search index=web sourcetype=b bpage=MAINPAGE | rename bIP as aIP | table aIP]&lt;/P&gt;

&lt;P&gt;| eval page = coalesce (apage, bpage)&lt;BR /&gt;
| eval ip = coalesce (aIP, bIP)&lt;/P&gt;

&lt;P&gt;| table page, ip&lt;/P&gt;

&lt;P&gt;So because the table of the subsearch is automatically the search parameters for the parent searches and I need to search for both results, I don’t see a better way than doing both searches twice and just rename the field name of the output table.&lt;/P&gt;

&lt;P&gt;Is there any way to reduce it to two subsearches in this case? Eg. renaming the fields without doing the search an additional time?&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jan 2018 18:41:41 GMT</pubDate>
    <dc:creator>DerBastler</dc:creator>
    <dc:date>2018-01-08T18:41:41Z</dc:date>
    <item>
      <title>Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298103#M89892</link>
      <description>&lt;P&gt;I need to do a search in two different sourcetypes and use the result to do additional searches in these queries.&lt;BR /&gt;
But I have the problem that, while both sourcetypes have similar values, they use different prefixes. So in sourcetype=A the ip is called aIP and in sourcetype=B the ip is called bIP respectively.&lt;/P&gt;

&lt;P&gt;So you could search with&lt;BR /&gt;
aIP=”192.168.0.1” OR bIp=”192.168.0.1”&lt;/P&gt;

&lt;P&gt;However if you want to use these ips from a subsearch of both of these tables it becomes problematic and I am not sure what the best solution is.&lt;BR /&gt;
So let’s assume I want to find the IPs used on a specific page called “MAINPAGE”. And use these IPs to search for other pages visited by them on both sources.&lt;BR /&gt;
I tried to minimize the code as far as possible. It might not make any sense anymore, but I hope it’s enough to bring across my point.&lt;/P&gt;

&lt;P&gt;Index=web (sourcetype=a OR sourcetype=b)&lt;BR /&gt;
[search index=web sourcetype=a apage=MAINPAGE | table aIP]&lt;/P&gt;

&lt;P&gt;OR&lt;BR /&gt;
[search index=web sourcetype=a apage=MAINPAGE | rename aIP as bIP | table bIP]&lt;BR /&gt;
OR&lt;BR /&gt;
[search index=web sourcetype=b bpage=MAINPAGE | table bIP]&lt;BR /&gt;
OR&lt;BR /&gt;
[search index=web sourcetype=b bpage=MAINPAGE | rename bIP as aIP | table aIP]&lt;/P&gt;

&lt;P&gt;| eval page = coalesce (apage, bpage)&lt;BR /&gt;
| eval ip = coalesce (aIP, bIP)&lt;/P&gt;

&lt;P&gt;| table page, ip&lt;/P&gt;

&lt;P&gt;So because the table of the subsearch is automatically the search parameters for the parent searches and I need to search for both results, I don’t see a better way than doing both searches twice and just rename the field name of the output table.&lt;/P&gt;

&lt;P&gt;Is there any way to reduce it to two subsearches in this case? Eg. renaming the fields without doing the search an additional time?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 18:41:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298103#M89892</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-08T18:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298104#M89893</link>
      <description>&lt;P&gt;why not something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Index=web (sourcetype=a OR sourcetype=b)
[search index=web sourcetype=a apage=MAINPAGE | eval bIP=aIP|table aIP bIP|format]
OR
[search index=web sourcetype=b bpage=MAINPAGE | eval aIP=bIP| table aIP bIP|format]
| eval page = coalesce (apage, bpage)
| eval ip = coalesce (aIP, bIP)
| table page, ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jan 2018 19:58:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298104#M89893</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2018-01-08T19:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298105#M89894</link>
      <description>&lt;P&gt;The problem in this case is, that both of the results are passed on with an AND.&lt;BR /&gt;
So if a subsearch returns &lt;BR /&gt;
|table aIP bIP&lt;BR /&gt;
that means that the main search now searches for aIP AND bIP.&lt;BR /&gt;
What I need in this case is an OR though as some of these fields might be null.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 22:41:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298105#M89894</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-08T22:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298106#M89895</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=web (sourcetype=a OR sourcetype=b)
[search index=web sourcetype=a apage=MAINPAGE | stats values(aIP) AS aIP | eval search="aIP=".mvjoin(aIP, " OR aIP=")." OR bIP=".mvjoin(aIP, " OR bIP=")]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When a subsearch returns a field named &lt;CODE&gt;search&lt;/CODE&gt;, that field's value will be dropped inline into your search.  This results in a search that looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=web (sourcetype=a OR sourcetype=b) aIP=1.2.3.4 OR aIP=4.3.2.1 OR bIP=1.2.3.4 OR bIP=4.3.2.1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or maybe:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=web
[search index=web sourcetype=a apage=MAINPAGE | stats values(aIP) AS aIP | eval search="(sourcetype=a (aIP=".mvjoin(aIP, " OR aIP=").")) OR (sourcetype=b (bIP=".mvjoin(aIP, " OR bIP=")."))"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which results in a search like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=web (sourcetype=a (aIP=1.2.3.4 OR aIP=4.3.2.1)) OR (sourcetype=b (bIP=1.2.3.4 OR bIP=4.3.2.1))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which might be a tad more efficient.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 22:51:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298106#M89895</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-08T22:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298107#M89896</link>
      <description>&lt;P&gt;Thanks! Can't say right now if it works or not, but that's definitely something I didn't come across and didn't test yet. Will try it asap!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 22:58:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298107#M89896</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-08T22:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298108#M89897</link>
      <description>&lt;P&gt;I just ran it, but it doesn't work.&lt;BR /&gt;
I tried the first and simpler variation, and fiddled around with it. Maybe there is some limit on how much can be in any field or something similar.&lt;BR /&gt;
It works for testing purpose if you insert an | eval aIP=specific single entry from valid result into it.&lt;BR /&gt;
But otherwise I guess that the following commands break down. Maybe there is some kind of limitation as the search "field" would contain thousands of numbers, likely almost a million characters.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2018 13:03:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298108#M89897</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-09T13:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298109#M89898</link>
      <description>&lt;P&gt;what about adding this after &lt;CODE&gt;format&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|rex mode=sed field=search "s/AND bIP/OR bIP/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2018 13:16:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298109#M89898</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2018-01-09T13:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298110#M89899</link>
      <description>&lt;P&gt;It sounds like you may be running into limitations of subsearch.  Subsearches finalize after 60 seconds (or 10k rows, though my previous answer worked around that specific limitation), so if your inside search takes too long to run you will get potentially incomplete results.&lt;/P&gt;

&lt;P&gt;Instead it's recommended you find a non-subsearch means to fetch your needed data, potentially like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=a OR sourcetype=b
| eval ip=if(sourcetype="a", aIP, bIP)
| stats values(apage) AS apage values(otherfield) AS otherfield BY ip
| search apage=MAINPAGE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2018 14:28:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298110#M89899</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-09T14:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298111#M89900</link>
      <description>&lt;P&gt;Actually the "format" itself already breaks the search. While the splunk documentations states that it's implicitly used (&lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Search/Changetheformatofsubsearchresults"&gt;https://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Search/Changetheformatofsubsearchresults&lt;/A&gt;)&lt;BR /&gt;
It's actually not. Well, the functionality is. But the search isn't generated the same way. It generates a big step in between which makes a 5 minute search into a 20 minute search, which then leads then to breaking subsearches.&lt;BR /&gt;
But I guess you can only use |rex if the format statement was used before. But as this breaks the search...&lt;BR /&gt;
(can be verified by increasing search time span. While it works with tiny timespans, at some point it takes so long that splunk starts to ignore subsearches)&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2018 15:46:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298111#M89900</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-09T15:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298112#M89901</link>
      <description>&lt;P&gt;Unfortunately that's not possible in my case. The initial data is too big. So the idea was to have rather "specific" subsearches, just leaving some thousand search values for the main search. Using the main search, grab everything and filter later on will use up too much data that the job gets stuck (and times out).&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2018 15:54:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298112#M89901</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-09T15:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298113#M89902</link>
      <description>&lt;P&gt;How long do these searches take to run:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=web sourcetype=a apage=MAINPAGE | stats values(aIP) AS aIP | eval search="aIP=".mvjoin(aIP, " OR aIP=")." OR bIP=".mvjoin(aIP, " OR bIP=")

index=web sourcetype=a apage=MAINPAGE | stats values(aIP) AS aIP | eval search="(sourcetype=a (aIP=".mvjoin(aIP, " OR aIP=").")) OR (sourcetype=b (bIP=".mvjoin(aIP, " OR bIP=")."))"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2018 16:01:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298113#M89902</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-09T16:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298114#M89903</link>
      <description>&lt;P&gt;We moved away from tackling the problem from this end now. I appreciate your help though.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 16:19:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298114#M89903</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-10T16:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298115#M89904</link>
      <description>&lt;P&gt;Have you tried creating 'Field Alias' for both &lt;CODE&gt;aIP&lt;/CODE&gt; and &lt;CODE&gt;bIP&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;If not, create one as  &lt;CODE&gt;src_ip&lt;/CODE&gt; and try this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=web (sourcetype=a OR sourcetype=b) | table page, src_ip&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;HTH, Mitesh.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 14:08:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298115#M89904</guid>
      <dc:creator>miteshvohra</dc:creator>
      <dc:date>2018-01-17T14:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch for multiple sourcetypes and fieldnames</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298116#M89905</link>
      <description>&lt;P&gt;Thank you! This works perfectly!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 00:57:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-for-multiple-sourcetypes-and-fieldnames/m-p/298116#M89905</guid>
      <dc:creator>DerBastler</dc:creator>
      <dc:date>2018-01-24T00:57:44Z</dc:date>
    </item>
  </channel>
</rss>

