<?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: Find records which both do and do not match user search criteria in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583750#M203281</link>
    <description>&lt;P&gt;Give this a shot:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="data"
| eval match_ct=IF(foo="A", 1, 0)
| eval match_ct=IF(bar="1", match_ct+1, match_ct)
| search match_ct IN (0, 2)
| stats dc(id) AS ids by user&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 04 Feb 2022 17:40:47 GMT</pubDate>
    <dc:creator>johnhuang</dc:creator>
    <dc:date>2022-02-04T17:40:47Z</dc:date>
    <item>
      <title>Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583747#M203280</link>
      <description>&lt;P&gt;I have a dataset that looks like: &lt;FONT face="courier new,courier"&gt;(id, foo, bar, user)&amp;nbsp;&lt;/FONT&gt;that I want to show results for on a dashboard.&lt;BR /&gt;Given an input combination of values for &lt;FONT face="courier new,courier"&gt;foo&lt;/FONT&gt;&amp;nbsp;and &lt;FONT face="courier new,courier"&gt;bar&lt;/FONT&gt;, I want to know which &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;s both&lt;BR /&gt;&amp;nbsp; &amp;nbsp; a) have at least one row that has BOTH of those values; and&lt;BR /&gt;&amp;nbsp; &amp;nbsp; b) have at least one row that has NEITHER of those values&lt;BR /&gt;and then count the number of such &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;s by &lt;FONT face="courier new,courier"&gt;user&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;For example, a search on &lt;FONT face="courier new,courier"&gt;(foo=A, bar=1)&lt;/FONT&gt;&amp;nbsp;for the data&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;foo&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;bar&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;user&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;1234&lt;/TD&gt;&lt;TD width="25%"&gt;A&lt;/TD&gt;&lt;TD width="25%"&gt;1&lt;/TD&gt;&lt;TD width="25%"&gt;admin&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;1234&lt;/TD&gt;&lt;TD width="25%"&gt;B&lt;/TD&gt;&lt;TD width="25%"&gt;2&lt;/TD&gt;&lt;TD width="25%"&gt;admin&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;other_user&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;abcd&lt;/TD&gt;&lt;TD width="25%"&gt;A&lt;/TD&gt;&lt;TD width="25%"&gt;1&lt;/TD&gt;&lt;TD width="25%"&gt;admin&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;abcd&lt;/TD&gt;&lt;TD width="25%"&gt;A&lt;/TD&gt;&lt;TD width="25%"&gt;2&lt;/TD&gt;&lt;TD width="25%"&gt;admin&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;would count &lt;FONT face="courier new,courier"&gt;1234&lt;/FONT&gt;, but not &lt;FONT face="courier new,courier"&gt;abcd&lt;/FONT&gt;, and return&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;&lt;STRONG&gt;user&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="50%"&gt;&lt;STRONG&gt;ids&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;admin&lt;/TD&gt;&lt;TD width="50%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;other_user&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each search parameter can be a single value or a comma-separated list. Empty values are permitted in up to one field at a time.&lt;/P&gt;&lt;P&gt;This is the closest I have been able to get:&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="courier new,courier"&gt;index="data" [&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; | tstats count where index="data" AND foo IN (A) AND bar IN (1) by id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; | fields id&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;] AND NOT (foo IN (A) OR bar IN (1))&lt;BR /&gt;| fields id, user&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| stats dc(id) as ids by user&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;I believe the query does what I want it to, but unfortunately am constrained by the hard limit of 10,500 results for subsearches. Is there a way to get the data I want without an intermediate command limiting my results?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 18:22:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583747#M203280</guid>
      <dc:creator>pbarna</dc:creator>
      <dc:date>2022-02-04T18:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583750#M203281</link>
      <description>&lt;P&gt;Give this a shot:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="data"
| eval match_ct=IF(foo="A", 1, 0)
| eval match_ct=IF(bar="1", match_ct+1, match_ct)
| search match_ct IN (0, 2)
| stats dc(id) AS ids by user&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 04 Feb 2022 17:40:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583750#M203281</guid>
      <dc:creator>johnhuang</dc:creator>
      <dc:date>2022-02-04T17:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583757#M203285</link>
      <description>&lt;P&gt;This is close, but I only want the &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;s that have rows where &lt;FONT face="courier new,courier"&gt;match_ct=0&lt;/FONT&gt; AND &lt;FONT face="courier new,courier"&gt;match_ct=2&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;A thought would be to do&lt;/P&gt;&lt;PRE&gt;| stats dc(match_ct) as matches by id&lt;BR /&gt;| search matches=2&lt;/PRE&gt;&lt;P&gt;But that loses user info. I updated the original post to show why&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| stats dc(match_ct) as matches by id, user &lt;/PRE&gt;&lt;P&gt;also wouldn't work.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 18:30:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583757#M203285</guid>
      <dc:creator>pbarna</dc:creator>
      <dc:date>2022-02-04T18:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583761#M203288</link>
      <description>&lt;PRE&gt;| eventstats dc(match_ct) as dc_matches by id&lt;BR /&gt;| search dc_matches=2&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 18:38:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583761#M203288</guid>
      <dc:creator>johnhuang</dc:creator>
      <dc:date>2022-02-04T18:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583762#M203289</link>
      <description>&lt;PRE&gt;index=whatever&lt;BR /&gt;| eval matchstate=case(in(foo,1,2,3) AND in(bar,4,5,6),1,NOT in(foo,1,2,3) AND NOT in(foo,4,5,6),2,1=1,0)&lt;BR /&gt;| stats values(matchstate) as matchstate by id user&lt;BR /&gt;| where matchstate=1 AND matchstate=2&lt;BR /&gt;| state count by user&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Feb 2022 18:57:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583762#M203289</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-02-04T18:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583776#M203293</link>
      <description>&lt;P&gt;I think this does what I'm looking for, but the job autofinalizes for even a relatively small amount of data.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 21:41:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583776#M203293</guid>
      <dc:creator>pbarna</dc:creator>
      <dc:date>2022-02-04T21:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583778#M203294</link>
      <description>&lt;P&gt;I probably edited my original post after this response, but doing&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| stats ... by id user&lt;/PRE&gt;&lt;P&gt;won't work.&lt;/P&gt;&lt;P&gt;I tried&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| eventstats values(matchstate) as matchstate by id&lt;/PRE&gt;&lt;P&gt;but similarly to the other proposed solution, the job autofinalizes for a relatively small amount of data and ultimately returns no results.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 21:44:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583778#M203294</guid>
      <dc:creator>pbarna</dc:creator>
      <dc:date>2022-02-04T21:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583783#M203296</link>
      <description>&lt;P&gt;What do you mean by "won't work"?&lt;/P&gt;&lt;P&gt;Also, stats and eventstats are not the same.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 22:10:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583783#M203296</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-02-04T22:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583786#M203297</link>
      <description>&lt;P&gt;Correct me if I'm wrong - using multiple in fields in &lt;FONT face="courier new,courier"&gt;by&lt;/FONT&gt; counts by unique value tuples of all those fields right?&amp;nbsp;&lt;BR /&gt;So, given the sample table I posted:&lt;/P&gt;&lt;PRE&gt;| eval matchstate=case(in(foo,1,2,3) AND in(bar,4,5,6),1,NOT in(foo,1,2,3) AND NOT in(foo,4,5,6),2,1=1,0&lt;BR /&gt;&lt;SPAN&gt;| stats values(matchstate) as matchstate by id user&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;will give back&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="37px"&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%" height="37px"&gt;&lt;STRONG&gt;foo&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%" height="37px"&gt;&lt;STRONG&gt;bar&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="12.5%" height="37px"&gt;&lt;STRONG&gt;user&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="12.5%" height="37px"&gt;&lt;STRONG&gt;matchstate&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="37px"&gt;1234&lt;/TD&gt;&lt;TD width="25%" height="37px"&gt;A&lt;/TD&gt;&lt;TD width="25%" height="37px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="37px"&gt;admin&lt;/TD&gt;&lt;TD width="12.5%" height="37px"&gt;1, 2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="37px"&gt;1234&lt;/TD&gt;&lt;TD width="25%" height="37px"&gt;C&lt;/TD&gt;&lt;TD width="25%" height="37px"&gt;3&lt;/TD&gt;&lt;TD width="12.5%" height="37px"&gt;other_user&lt;/TD&gt;&lt;TD width="12.5%" height="37px"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="40px"&gt;abcd&lt;/TD&gt;&lt;TD width="25%" height="40px"&gt;A&lt;/TD&gt;&lt;TD width="25%" height="40px"&gt;1&lt;/TD&gt;&lt;TD width="12.5%" height="40px"&gt;admin&lt;/TD&gt;&lt;TD width="12.5%" height="40px"&gt;&lt;P&gt;1, 0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| where matchstate=1 AND matchstate=2&lt;/PRE&gt;&lt;P&gt;will drop the row for &lt;FONT face="courier new,courier"&gt;other_user&lt;/FONT&gt;, when I want my results to include that row.&lt;/P&gt;&lt;P&gt;I mentioned &lt;FONT face="courier new,courier"&gt;eventstats&lt;/FONT&gt; because I would still need the &lt;FONT face="courier new,courier"&gt;user&lt;/FONT&gt; column after doing the &lt;FONT face="courier new,courier"&gt;stats values&lt;/FONT&gt;, but can't include it using &lt;FONT face="courier new,courier"&gt;by&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 22:31:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583786#M203297</guid>
      <dc:creator>pbarna</dc:creator>
      <dc:date>2022-02-04T22:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583788#M203299</link>
      <description>&lt;P&gt;The other_user doesn't match your specs.&lt;/P&gt;&lt;P&gt;Let me quote you. For each user you wanted&lt;/P&gt;&lt;P&gt;"which &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;s both&lt;BR /&gt;&amp;nbsp; &amp;nbsp; a) have at least one row that has BOTH of those values; and&lt;BR /&gt;&amp;nbsp; &amp;nbsp; b) have at least one row that has NEITHER of those values"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 22:53:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583788#M203299</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-02-04T22:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583793#M203301</link>
      <description>&lt;P&gt;Ah sorry if I was unclear, I know this problem is a little convoluted.&lt;/P&gt;&lt;P&gt;I want to find the &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;s that fulfil the conditions *regardless of &lt;FONT face="courier new,courier"&gt;user&lt;/FONT&gt;*, THEN count the number of such &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;s by &lt;FONT face="courier new,courier"&gt;user&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;VS count the &lt;FONT face="courier new,courier"&gt;id&lt;/FONT&gt;s that fulfil the conditions for a single &lt;FONT face="courier new,courier"&gt;user&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;For example, if you removed the second row of my test data, the result would be the same (returning both admin and other_user).&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 23:10:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583793#M203301</guid>
      <dc:creator>pbarna</dc:creator>
      <dc:date>2022-02-04T23:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Find records which both do and do not match user search criteria</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583795#M203303</link>
      <description>&lt;P&gt;Ok. That's a bit clearer now. Still, the solution will be similar if I understood you correctly this time&lt;/P&gt;&lt;PRE&gt;index=whatever&lt;BR /&gt;| eval matchstate=case(in(foo,1,2,3) AND in(bar,4,5,6),1,NOT in(foo,1,2,3) AND NOT in(foo,4,5,6),2,1=1,0)&lt;BR /&gt;| stats values(matchstate) as matchstate values(user) as users by id&lt;BR /&gt;| where matchstate=1 AND matchstate=2&lt;BR /&gt;| fields - matchstate&lt;BR /&gt;| mvexpand user&lt;BR /&gt;| state count by user&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 23:26:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-records-which-both-do-and-do-not-match-user-search-criteria/m-p/583795#M203303</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-02-04T23:26:52Z</dc:date>
    </item>
  </channel>
</rss>

