<?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: Subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/682026#M233033</link>
    <description>&lt;P&gt;Thank you for all updates.&lt;BR /&gt;Due to large number of devices I decided to use method #2 from the last post.&lt;BR /&gt;My SPL looks like&lt;BR /&gt;-------&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=index2 OR (index=index1 sourcetype="metadata" "health.severity"!=NULL)
| eval IP_ADDRESS=if(index=index1, interfaces.address, PRIMARY_IP_ADDRESS) ```PRIMARY_IP_ADDRESS is from index2 to match interfaces.address from index1111
| stats dc(index) as indexes values(DISCOVERED_OS) as DISCOVERED_OS by interfaces.address
| where indexes=2
| table IP_ADDRESS
&lt;/LI-CODE&gt;
&lt;P&gt;________&lt;BR /&gt;&lt;BR /&gt;Query runs with no errors, but produced 0(zero) events &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you, Leon&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2024 17:35:04 GMT</pubDate>
    <dc:creator>bigll</dc:creator>
    <dc:date>2024-03-26T17:35:04Z</dc:date>
    <item>
      <title>Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/679313#M232222</link>
      <description>&lt;P&gt;I have two SPL&lt;BR /&gt;&lt;BR /&gt;#1&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=index1 service IN (22, 53, 80, 8080)
| table src_ip&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;#2&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=index2
dev_ip IN ( value from #1 src_ip)
|table dev_ip, OS_Type&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;----------------------&lt;BR /&gt;I try to create a single SPL with sub search&lt;BR /&gt;I.e.&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=index2
dev_ip IN ([search  index=index1 service IN (22, 53, 80, 8080)
| table src_ip])
|table dev_ip, OS_Type&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I get an error message&lt;BR /&gt;&lt;SPAN&gt;Error in 'search' command: Unable to parse the search: Right hand side of IN must be a collection of literals. '(src_ip = "130.197.32.155")' is not a literal.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 16:55:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/679313#M232222</guid>
      <dc:creator>bigll</dc:creator>
      <dc:date>2024-03-01T16:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/679323#M232223</link>
      <description>&lt;P&gt;You should change this like&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=index2
dev_ip IN ([search  index=index1 service IN (22, 53, 80, 8080)
| table src_ip
| rename src_ip as search])
|table dev_ip, OS_Type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 17:11:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/679323#M232223</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-03-01T17:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/679427#M232272</link>
      <description>&lt;P&gt;You don't need to use the IN construct when using subsearches, as the default returned from a subsearch is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;field=A OR field=B or field=C...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so in practice you can just do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=index2 [
  search  index=index1 service IN (22, 53, 80, 8080)
  | table src_ip
  | rename src_ip as dev_ip
]
| table dev_ip, OS_Type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however, how many src_ips are you likely to get back from this subsearch? If you get a large number, this may not perform well at all. In that case you will have to approach the problem in a different way, e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=index2 OR (index=index1 service IN (22, 53, 80, 8080)) 
``` Creates a common dev_ip field which is treated as the common field 
    between the two indexes ```
| eval dev_ip=if(index=index2, dev_ip, src_ip)
``` Now we need the data to be seen in both indexes, so count the indexes
    and collect the OS_Type values and split by that common dev_ip field ```
| stats dc(index) as indexes values(OS_Type) as OS_Type by dev_ip
``` And this just ensures we have seen the data from both places ```
| where indexes=2
| fields - indexes&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A third way to attack this type of problem is using a lookup, where you maintain a list of the src_ips you want to match for in a lookup table.&lt;/P&gt;&lt;P&gt;Which one you end up with, will depend on your data and its volume as they will have different performance characteristics.&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2024 22:17:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/679427#M232272</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-03-03T22:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/682026#M233033</link>
      <description>&lt;P&gt;Thank you for all updates.&lt;BR /&gt;Due to large number of devices I decided to use method #2 from the last post.&lt;BR /&gt;My SPL looks like&lt;BR /&gt;-------&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=index2 OR (index=index1 sourcetype="metadata" "health.severity"!=NULL)
| eval IP_ADDRESS=if(index=index1, interfaces.address, PRIMARY_IP_ADDRESS) ```PRIMARY_IP_ADDRESS is from index2 to match interfaces.address from index1111
| stats dc(index) as indexes values(DISCOVERED_OS) as DISCOVERED_OS by interfaces.address
| where indexes=2
| table IP_ADDRESS
&lt;/LI-CODE&gt;
&lt;P&gt;________&lt;BR /&gt;&lt;BR /&gt;Query runs with no errors, but produced 0(zero) events &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you, Leon&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 17:35:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/682026#M233033</guid>
      <dc:creator>bigll</dc:creator>
      <dc:date>2024-03-26T17:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/682202#M233068</link>
      <description>&lt;P&gt;This statement&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval IP_ADDRESS=if(index=index1, interfaces.address, PRIMARY_IP_ADDRESS)&lt;/LI-CODE&gt;&lt;P&gt;will need to have single quotes round the interfaces.address, as eval statements need fields with non-simple characters to be single quoted, in this case the full-stop (.)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval IP_ADDRESS=if(index=index1, 'interfaces.address', PRIMARY_IP_ADDRESS)&lt;/LI-CODE&gt;&lt;P&gt;Note also that &lt;STRONG&gt;index=index1&lt;/STRONG&gt; would need to be &lt;STRONG&gt;index="index1"&amp;nbsp;&lt;/STRONG&gt;as you are looking for the value of index to be the string index1 rather than comparing field index to field index1.&lt;/P&gt;&lt;P&gt;As for debugging queries, if you just remove the 'where' clause, you can see what you are getting and what the value of indexes is.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 22:24:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch/m-p/682202#M233068</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-03-27T22:24:20Z</dc:date>
    </item>
  </channel>
</rss>

