<?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: Filter specific values from a field in main search by values from same field in subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678170#M231928</link>
    <description>&lt;P&gt;Using join is not a Splunk way of doing things, generally you would use stats. I'm not entirely clear on what fields exist in what indexes in your example. Does InstanceId exist in index=main data - that is what you are joining on&lt;/P&gt;&lt;P&gt;From your description it sounds like all you want are those InstanceIds that come from the subsearch, so maybe I'm missing something&lt;/P&gt;&lt;P&gt;If you are looking to find only those ResourceId where ResourceId=InstanceId from your current subsearch, but are also looking for other information, then&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main ResourceId=* OR (index=other type=instance earliest=-2h)
| eval InstanceId=coalesce(ResourceId, InstanceId)
| stats values(*) as * values(index) as indexes count by InstanceId
| where mvcount(indexes)=2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Feb 2024 09:26:58 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2024-02-21T09:26:58Z</dc:date>
    <item>
      <title>Filter specific values from a field in main search by values from same field in subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678124#M231909</link>
      <description>&lt;P&gt;In my search I have a field (ResourceId) that contains various cloud resource values. One of these values is InstanceId. The subsearch is returning a list of "active" instances. What I ultimately need to do is filter out only those InstanceIds from the ResourceIds field that DO NOT match the InstanceIds returned from the subsearch (the active instances), while keeping all other values in the ResourceId field.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sample ResourceId values:&lt;/STRONG&gt;&lt;BR /&gt;i-987654321abcdefg (active; WAS returned by subsearch)&lt;BR /&gt;i-123abcde456abcde (inactive; was NOT a returned value from subsearch)&lt;BR /&gt;bucket-name&lt;BR /&gt;sg-12423adssvd&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Intended Output:&lt;/STRONG&gt;&lt;BR /&gt;i-987654321abcdefg&lt;BR /&gt;bucket-name&lt;BR /&gt;sg-12423adssvd&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Search (in progress):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main ResourceId=*
| join InstanceId type=inner [search index=other type=instance earliest=-2h]
| eval InstanceId=if(in(ResourceId, InstanceId), InstanceId, "NULL")
| table InstanceId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 20:00:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678124#M231909</guid>
      <dc:creator>ea-2023</dc:creator>
      <dc:date>2024-02-20T20:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Filter specific values from a field in main search by values from same field in subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678170#M231928</link>
      <description>&lt;P&gt;Using join is not a Splunk way of doing things, generally you would use stats. I'm not entirely clear on what fields exist in what indexes in your example. Does InstanceId exist in index=main data - that is what you are joining on&lt;/P&gt;&lt;P&gt;From your description it sounds like all you want are those InstanceIds that come from the subsearch, so maybe I'm missing something&lt;/P&gt;&lt;P&gt;If you are looking to find only those ResourceId where ResourceId=InstanceId from your current subsearch, but are also looking for other information, then&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=main ResourceId=* OR (index=other type=instance earliest=-2h)
| eval InstanceId=coalesce(ResourceId, InstanceId)
| stats values(*) as * values(index) as indexes count by InstanceId
| where mvcount(indexes)=2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 09:26:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678170#M231928</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-02-21T09:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Filter specific values from a field in main search by values from same field in subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678249#M231948</link>
      <description>&lt;P&gt;I really appreciate the suggestion. You do seem to get what I'm after, though the mvcount(indexes) returned no results. It seems so simple to me conceptually, but finding it very frustrating to try and wrap my head around "how splunk does it".&amp;nbsp;I'm trying to include just the InstanceIds seen in both indexes while keeping the rest of the values from ResourceId in index=main.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Index=main contains many different values in ResourceId (some of which are instance IDs).&lt;BR /&gt;Index=other has a field called InstanceId.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This works, but I am not sure how to filter the MV index results (where mvcount(index)=2 did not work)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=main ResourceId=i-*) OR (index=other type=instance earliest=-2h)
| eval InstanceId=coalesce(ResourceId, InstanceId)
| stats values(index) as index by InstanceId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to use if/match, which sounds like it is exactly what I need, but it looks like you can't specify dynamic values for the match.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=main ResourceId=i-*) OR (index=other type=instance earliest=-2h)
| eval InstanceId=if(match(ResourceId, InstanceId, ResourceId, "null"))
| stats values(index) as index by InstanceId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 19:10:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678249#M231948</guid>
      <dc:creator>ea-2023</dc:creator>
      <dc:date>2024-02-21T19:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Filter specific values from a field in main search by values from same field in subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678283#M231957</link>
      <description>&lt;P&gt;This statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats values(index) as index by InstanceId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;should certainly give you a field called index which will contain main/other or both&lt;/P&gt;&lt;P&gt;Doing&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats values(*) as * dc(index) as index_count by InstanceId&lt;/LI-CODE&gt;&lt;P&gt;would give you all the values of every field from both indexes and a field called index_count that would contain a 1 or 2&lt;/P&gt;&lt;P&gt;You can't match the resource id against the instanceid as the events are not yet "joined" together, so there will either be a ResourceId (from index=main) OR an InstanceId (from index=other), so the coalesce+stats will join the two datasets together on that now common field (due to coalesce).&lt;/P&gt;&lt;P&gt;Effectively what you are saying is that after the stats, it will show, for each InstanceId (where InstanceId has come from ResourceId in index=main), the values of the indexes those IDs were found in.&lt;/P&gt;&lt;P&gt;After the stats you can then match as needed, so I believe what you are trying to do is to then say&amp;nbsp;&lt;/P&gt;&lt;P&gt;"I need to only show results, where a ResourceId from index=main has also been found as InstanceId from index=other.&lt;/P&gt;&lt;P&gt;So, the logic to decide that is&lt;/P&gt;&lt;P&gt;mvcount(index)=2 (this means it was in both indexes). You could use index_count from the dc(index) example above = that is the same as doing the mvcount.&lt;/P&gt;&lt;P&gt;Doing values(*) as * is simply a way to carry through all fields combined from both indexes when joining the data together - as you have tried the stats values(index) as index... that should simply carry forward the main+other to that field.&lt;/P&gt;&lt;P&gt;Can you given an example of the data you have in both and a search result that highlights what you are getting.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 21:47:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678283#M231957</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-02-21T21:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Filter specific values from a field in main search by values from same field in subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678371#M231983</link>
      <description>&lt;P&gt;I think I may not be explaining a key part of this well enough (or if I am misunderstanding your explanation, I'm sorry!). I need ALL ResourceIds from index=main. The only values I need to filter out are instance IDs (i.e. i-1234567abcdef) that are NOT found in index=other.&lt;BR /&gt;&lt;BR /&gt;So let's say index=main ResourceId=* returns:&lt;BR /&gt;i-1234567abcdef&lt;BR /&gt;i-abcdef1234567&lt;BR /&gt;sg-12345abcde&lt;BR /&gt;etc. (any other value that is not an instance ID)&lt;BR /&gt;&lt;BR /&gt;and the index=other search returns InstanceId:&lt;BR /&gt;i-abcdef1234567&lt;BR /&gt;&lt;BR /&gt;I need the results to be (filtered out&amp;nbsp;i-1234567abcdef because it was not returned by index=other):&lt;BR /&gt;i-abcdef1234567&lt;BR /&gt;sg-12345abcde&lt;BR /&gt;&lt;BR /&gt;So I guess a way to think about this is that I am trying to remove any value from ResourceId that matches the string "i-*" IF it was NOT found in index=other, and THEN coalesce ResourceId and InstanceId into a single field.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 19:29:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678371#M231983</guid>
      <dc:creator>ea-2023</dc:creator>
      <dc:date>2024-02-22T19:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Filter specific values from a field in main search by values from same field in subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678621#M232046</link>
      <description>&lt;P&gt;Your example is a little unclear, because it stats index=other has &lt;STRONG&gt;&lt;SPAN&gt;i-abcdef1234567 &lt;/SPAN&gt;&lt;/STRONG&gt;but in the next statement sats it is filtered out&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;i-abcdef1234567&lt;/SPAN&gt;&lt;/STRONG&gt;&amp;nbsp; because it was NOT in index=other&lt;/P&gt;&lt;P&gt;Hopefully the following example demonstrates the principle. I am using makeresults to simulate your data set. The stats values combines the two and then the where clause is what you use for your exclusion logic.&lt;/P&gt;&lt;P&gt;If that is not correct based on the above discrepancy, adjust as necessary. You can remove the where clause to see what the data looks like first&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval index="main", ResourceId=split("i-1234567abcdef,i-abcdef1234567,sg-12345abcde,abc", ",")
| mvexpand ResourceId
| append [
  | makeresults
```
and the index=other search returns InstanceId:
i-abcdef1234567
```
  | eval index="other", InstanceId=split("i-abcdef1234567,i-abcdef1234569",",")
]
| fields - _time
``` The above is just simulating your data setup ```
| eval ResourceId=coalesce(ResourceId, InstanceId)
| stats values(index) as index dc(index) as indexes by ResourceId
| where (indexes=1 AND index="main") OR indexes=2 
```
I need the results to be (filtered out i-1234567abcdef because it was not returned by index=other):
i-abcdef1234567
sg-12345abcde```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 22:49:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-specific-values-from-a-field-in-main-search-by-values/m-p/678621#M232046</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-02-25T22:49:51Z</dc:date>
    </item>
  </channel>
</rss>

