<?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: How to append search results but also filter one query with the other in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/700270#M237654</link>
    <description>&lt;P&gt;So the best performing solution I could come up with was something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=ind1 earliest=-1d field1=abc field2 IN
 ([search index=ind1 earliest=-1d "A" field1=xyz | stats count by field2 | fields field2 | rename field2 as query | format mvsep="" "" "" "" "" "" "" | replace "NOT ()" WITH ""]) |
 append [search index=ind1 earliest=-1d "A" field1=xyz]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This way, the parent query is running with the additional filtering provided by the subquery.&amp;nbsp; One thing I was wondering was whether the search results of "search index=ind1 earliest=-1d "A" field1=xyz" could be stored to not have to run it twice.&amp;nbsp; Is that possible?&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 20:43:25 GMT</pubDate>
    <dc:creator>JBMiller83</dc:creator>
    <dc:date>2024-09-26T20:43:25Z</dc:date>
    <item>
      <title>How to append search results but also filter one query with the other</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699228#M237389</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm trying to write a query where I provide a key identifier (say "A"), and the query both finds matching results, but also uses a field from those results as a filter to another query that provides additional data that's needed.&amp;nbsp; &amp;nbsp;Obfuscating some things, this is the idea, and the closest I've gotten:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=ind1 earliest=-1d field1=abc | append [search index=ind1 earliest=-1d "A" field1=xyz | rename field2 as f2] | where field2=f2 OR field1="xyz"&lt;/LI-CODE&gt;
&lt;P&gt;The idea is that results where field1=xyz and contain "A" have another field, "field2", that is present and has a matching value when field1=xyz or field1=abc.&amp;nbsp; So I want to be able to search based "A" and get back results where field1=xyz or field1=abc where field2 matches between those 2 sets.&lt;/P&gt;
&lt;P&gt;I do think a join would probably work here, but I've heard there can be performance issues with that so I was trying to avoid that.&amp;nbsp; It seems to me that I can't use "where field2=f2", and it also seems the parent search is pulling in a lot of data because of the generally broad terms (I suppose because the piped where command is applied after the fact).&amp;nbsp; Any ideas of how to write this performantly?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 22:00:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699228#M237389</guid>
      <dc:creator>JBMiller83</dc:creator>
      <dc:date>2024-09-16T22:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to append search results but also filter one query with the other</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699231#M237390</link>
      <description>&lt;P&gt;Try something along these lines&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval keep_xyz=if(searchmatch("A") AND field1="xyz","true",null())
| eval keep_abc=if(field1="abc","true",null())
| eventstats values(keep_abc) as keep_abc values(keep_xyz) as keep_xyz by field2
| where keep_xyz="true" AND keep_abc="true"&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 Sep 2024 22:30:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699231#M237390</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-09-16T22:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to append search results but also filter one query with the other</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699299#M237408</link>
      <description>&lt;P&gt;&lt;EM&gt;Replied in the wrong thread, ignore!&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 18:08:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699299#M237408</guid>
      <dc:creator>JBMiller83</dc:creator>
      <dc:date>2024-09-17T18:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to append search results but also filter one query with the other</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699305#M237412</link>
      <description>&lt;P&gt;That does seem like that would work as far as getting the results I want, though it leaves one of my issues unsolved.&amp;nbsp; The parent query "index=ind1 earliest=-1d field1=abc" returns many, many results without the inclusion of some filter on field2.&amp;nbsp; My initial approach (plus your fix for it) filter those results after that broad search is done which isn't great from a performance perspective.&amp;nbsp; Perhaps I'm better off just using a join at that point, not sure.&lt;/P&gt;&lt;P&gt;Anyway, thanks for the reply&lt;SPAN&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 18:08:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/699305#M237412</guid>
      <dc:creator>JBMiller83</dc:creator>
      <dc:date>2024-09-17T18:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to append search results but also filter one query with the other</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/700270#M237654</link>
      <description>&lt;P&gt;So the best performing solution I could come up with was something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=ind1 earliest=-1d field1=abc field2 IN
 ([search index=ind1 earliest=-1d "A" field1=xyz | stats count by field2 | fields field2 | rename field2 as query | format mvsep="" "" "" "" "" "" "" | replace "NOT ()" WITH ""]) |
 append [search index=ind1 earliest=-1d "A" field1=xyz]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This way, the parent query is running with the additional filtering provided by the subquery.&amp;nbsp; One thing I was wondering was whether the search results of "search index=ind1 earliest=-1d "A" field1=xyz" could be stored to not have to run it twice.&amp;nbsp; Is that possible?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 20:43:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-results-but-also-filter-one-query-with-the/m-p/700270#M237654</guid>
      <dc:creator>JBMiller83</dc:creator>
      <dc:date>2024-09-26T20:43:25Z</dc:date>
    </item>
  </channel>
</rss>

