<?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 filter in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-filter/m-p/455413#M128769</link>
    <description>&lt;P&gt;You should create a field extraction for the &lt;EM&gt;activityId&lt;/EM&gt; field, so that it gets extracted automatically for all events. This way, you don't need the rex command in your search.&lt;/P&gt;

&lt;P&gt;You are right: You should use a subsearch for this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="firstHost" NOT [search index="myIndex" host="firstHost" "Request blocked because of blacklisted user" | table activityId] ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, with the rex command (I improved the regex a little):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="firstHost" | rex field=_raw "\|(?&amp;lt;activityId&amp;gt;[^\|]+)\|" | search NOT [search index="myIndex" host="firstHost" "Request blocked because of blacklisted user" | rex field=_raw "\|(?&amp;lt;activityId&amp;gt;[^\|]+)\|" | table activityId] ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will filter all events in the base search which have a matching activityId in the subsearch.&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2019 12:45:25 GMT</pubDate>
    <dc:creator>whrg</dc:creator>
    <dc:date>2019-05-15T12:45:25Z</dc:date>
    <item>
      <title>Subsearch filter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-filter/m-p/455412#M128768</link>
      <description>&lt;P&gt;In an index for a specific host I have log lines like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2019-05-15T06:09:56+00:00|6eb44e3c-d93e-4a43-b3f0-560a03459233|some logging
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the timestamp, an id and the actual log line.&lt;/P&gt;

&lt;P&gt;And for another host in the same index i have log lines like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2019-05-15T06:09:56,241+0000|6eb44e3c-d93e-4a43-b3f0-560a03459233|Request blocked because of blacklisted user.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is a timestamp, an id and the actual log line.&lt;/P&gt;

&lt;P&gt;I have a query for the first host that counts the number of 5xx response codes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="firstHost" responseCode &amp;gt;199 "some search field" | rangemap field=responseCode 2xx=200-299 3xx=300-399 4xx=400-499 5xx=500-599 | rename range AS "Http Status" | search "Http Status"=5xx | append [stats count | eval _time=-1 | where count=0 | fields - count] | timechart span=15m count by "Http Status"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My problem is that this query is counting more occurrences than I'd like. I would like to restrict the counted lines to lines that do not have an activity id for which the activity id also appears on the second host on a log line that contains "Request blocked because of blacklisted user".&lt;BR /&gt;
So: &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Search first host and extract  activityId of each log line and return list of activity ids: &lt;CODE&gt;rex field=_raw  "\|(?&amp;lt;activityId&amp;gt;.*?(?=\|)\|)" | table activityId&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Remove  an activity id out of the list if it occurs on the second host in the same line as "Request blocked because of blacklisted user" &lt;/LI&gt;
&lt;LI&gt;Execute my above query but only for log lines that contain an activity id from those that are still in the list.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I assume this'll require a subsearch because it uses search results from one host to filter results on another host. But I do not know where to start to create a query like this.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 07:47:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-filter/m-p/455412#M128768</guid>
      <dc:creator>maartendhondt</dc:creator>
      <dc:date>2019-05-15T07:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch filter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-filter/m-p/455413#M128769</link>
      <description>&lt;P&gt;You should create a field extraction for the &lt;EM&gt;activityId&lt;/EM&gt; field, so that it gets extracted automatically for all events. This way, you don't need the rex command in your search.&lt;/P&gt;

&lt;P&gt;You are right: You should use a subsearch for this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="firstHost" NOT [search index="myIndex" host="firstHost" "Request blocked because of blacklisted user" | table activityId] ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, with the rex command (I improved the regex a little):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="firstHost" | rex field=_raw "\|(?&amp;lt;activityId&amp;gt;[^\|]+)\|" | search NOT [search index="myIndex" host="firstHost" "Request blocked because of blacklisted user" | rex field=_raw "\|(?&amp;lt;activityId&amp;gt;[^\|]+)\|" | table activityId] ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will filter all events in the base search which have a matching activityId in the subsearch.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 12:45:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-filter/m-p/455413#M128769</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2019-05-15T12:45:25Z</dc:date>
    </item>
  </channel>
</rss>

