<?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 Filtering data for stats purpose in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-for-stats-purpose/m-p/671006#M229968</link>
    <description>&lt;P&gt;I am using Splunk 9.0.4 and I need to make a query where I extract data from a main search.&lt;BR /&gt;So I am interested in results from the main search:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;stage=it sourcetype=some_type NOT trid="&amp;lt;null&amp;gt;" reqest="POST /as/*/auth *"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;But then I need filter out results from the main search, using a subsearch that operates on a different data set, using a value from a field from the main search, let's call it trid, and trid is a string that might be part of a&amp;nbsp; value called message in a subsearch. There might be more results in the subsearch, but if there is at least one result in a subsearch then the result from the main search stays in the main search, if not it should not be included in the main search.&lt;BR /&gt;&lt;BR /&gt;So I am interested only in the results from the main search, and the subsearch is only used to filter out some of them that does not match.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;stage=it sourcetype=some_type NOT trid="&amp;lt;null&amp;gt;" reqest="POST /as/*/auth *"
| fields trid
[
    search stage=it sourcetype=another_type
    | eval matches_found=if(match(message, "ID=PASSLOG_" + trid), 1, 0)
    | stats max(matches_found) as matches_found
]
| where matches_found&amp;gt;0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;After a few hours I cannot figure out how to make it. What is wrong with it? Please advise.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2023 12:09:23 GMT</pubDate>
    <dc:creator>ripson</dc:creator>
    <dc:date>2023-12-06T12:09:23Z</dc:date>
    <item>
      <title>Filtering data for stats purpose</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-for-stats-purpose/m-p/671006#M229968</link>
      <description>&lt;P&gt;I am using Splunk 9.0.4 and I need to make a query where I extract data from a main search.&lt;BR /&gt;So I am interested in results from the main search:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;stage=it sourcetype=some_type NOT trid="&amp;lt;null&amp;gt;" reqest="POST /as/*/auth *"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;But then I need filter out results from the main search, using a subsearch that operates on a different data set, using a value from a field from the main search, let's call it trid, and trid is a string that might be part of a&amp;nbsp; value called message in a subsearch. There might be more results in the subsearch, but if there is at least one result in a subsearch then the result from the main search stays in the main search, if not it should not be included in the main search.&lt;BR /&gt;&lt;BR /&gt;So I am interested only in the results from the main search, and the subsearch is only used to filter out some of them that does not match.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;stage=it sourcetype=some_type NOT trid="&amp;lt;null&amp;gt;" reqest="POST /as/*/auth *"
| fields trid
[
    search stage=it sourcetype=another_type
    | eval matches_found=if(match(message, "ID=PASSLOG_" + trid), 1, 0)
    | stats max(matches_found) as matches_found
]
| where matches_found&amp;gt;0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;After a few hours I cannot figure out how to make it. What is wrong with it? Please advise.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 12:09:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-for-stats-purpose/m-p/671006#M229968</guid>
      <dc:creator>ripson</dc:creator>
      <dc:date>2023-12-06T12:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data for stats purpose</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-for-stats-purpose/m-p/671018#M229970</link>
      <description>&lt;P&gt;Subsearches execute before main searches (although there are exceptions), therefore trid from the main search is not available in the subsearch. However, you could try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;stage=it sourcetype=some_type NOT trid="&amp;lt;null&amp;gt;" reqest="POST /as/*/auth *"
[
    search stage=it sourcetype=another_type
    | rex field=message "ID=PASSLOG_(?&amp;lt;trid&amp;gt;\d+)"
    | stats count by trid
    | fields trid
]&lt;/LI-CODE&gt;&lt;P&gt;Here I have assumed trid is numeric - if not, you should define a pattern that will allow rex to extract the trid from the message field&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 14:28:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-for-stats-purpose/m-p/671018#M229970</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-12-06T14:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data for stats purpose</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filtering-data-for-stats-purpose/m-p/671023#M229972</link>
      <description>&lt;P&gt;Thank you so much! This is UUID actually but I have added a pattern and it works perfectly!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 15:06:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filtering-data-for-stats-purpose/m-p/671023#M229972</guid>
      <dc:creator>ripson</dc:creator>
      <dc:date>2023-12-06T15:06:18Z</dc:date>
    </item>
  </channel>
</rss>

