<?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 How to create a search that compares two lists of field values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130899#M35681</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm looking for a possibility to compare two lists of field values from two different sourecetypes. For that I started a search like:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=test1&lt;/CODE&gt; OR  &lt;CODE&gt;sourcetype=test2&lt;/CODE&gt; &lt;CODE&gt;| rex field=_raw "field1"&lt;/CODE&gt; &lt;CODE&gt;| rex field=_raw "field2"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;After this search, I get  &lt;CODE&gt;field1&lt;/CODE&gt; and  &lt;CODE&gt;field2&lt;/CODE&gt; and both have multiple values.&lt;BR /&gt;
Now I want to check if the values of  &lt;CODE&gt;field1&lt;/CODE&gt; contain the values of  &lt;CODE&gt;field2&lt;/CODE&gt;.&lt;BR /&gt;
The end result should be a list of values from  &lt;CODE&gt;field2&lt;/CODE&gt; that are not included in the values list of  &lt;CODE&gt;field1&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I thought of something like this Python code, but with Splunk functions:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for value in field2.values:
    if value NOT in field1.values:
        print(value)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for any suggestions!&lt;/P&gt;

&lt;P&gt;Greetings&lt;/P&gt;</description>
    <pubDate>Mon, 14 Apr 2014 14:02:41 GMT</pubDate>
    <dc:creator>C_Sparn</dc:creator>
    <dc:date>2014-04-14T14:02:41Z</dc:date>
    <item>
      <title>How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130899#M35681</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm looking for a possibility to compare two lists of field values from two different sourecetypes. For that I started a search like:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=test1&lt;/CODE&gt; OR  &lt;CODE&gt;sourcetype=test2&lt;/CODE&gt; &lt;CODE&gt;| rex field=_raw "field1"&lt;/CODE&gt; &lt;CODE&gt;| rex field=_raw "field2"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;After this search, I get  &lt;CODE&gt;field1&lt;/CODE&gt; and  &lt;CODE&gt;field2&lt;/CODE&gt; and both have multiple values.&lt;BR /&gt;
Now I want to check if the values of  &lt;CODE&gt;field1&lt;/CODE&gt; contain the values of  &lt;CODE&gt;field2&lt;/CODE&gt;.&lt;BR /&gt;
The end result should be a list of values from  &lt;CODE&gt;field2&lt;/CODE&gt; that are not included in the values list of  &lt;CODE&gt;field1&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I thought of something like this Python code, but with Splunk functions:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for value in field2.values:
    if value NOT in field1.values:
        print(value)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for any suggestions!&lt;/P&gt;

&lt;P&gt;Greetings&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2014 14:02:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130899#M35681</guid>
      <dc:creator>C_Sparn</dc:creator>
      <dc:date>2014-04-14T14:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130900#M35682</link>
      <description>&lt;P&gt;Hi C_Sparn,&lt;/P&gt;

&lt;P&gt;try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype="splunkd" OR sourcetype="splunk_web_access" 
| streamstats count by status, idx, sourcetype 
| stats values(idx) AS idx, values(status) AS status, values(sourcetype) AS sourcetype 
| mvexpand status 
| eval Status = if(match(idx,status), "MATCH", "NO MATCH") 
| table status, idx, Status
| where Status="NO MATCH"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Update: this is a run everywhere example of the final search used to get the expected result. streamstats hint came from a originally hint to use stats made by @somesoni2 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;hope this helps to get you started ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2014 14:13:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130900#M35682</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-14T14:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130901#M35683</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Thank you for the answer.It seems to be the right search but now i have another problem.&lt;BR /&gt;
The search is loading for 20 minutes now but it has just 10%!But i think that splunk has a problem with 2 mvexpand options in this search, because the results have 4500 and 2100 values.&lt;BR /&gt;
You can see that because &lt;/P&gt;

&lt;P&gt;| stats values(field1) AS t1 values(field2) AS t2| mvexpand t1 | mvexpand t2 |table t1&lt;/P&gt;

&lt;P&gt;is already very slow.&lt;BR /&gt;
Maybe some values are twice in the lists.&lt;BR /&gt;
How can i delete dublicate values?&lt;BR /&gt;
Or is there maybe another reason why splunk is that slow?&lt;BR /&gt;
Greeting&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2014 15:26:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130901#M35683</guid>
      <dc:creator>C_Sparn</dc:creator>
      <dc:date>2014-04-14T15:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130902#M35684</link>
      <description>&lt;P&gt;Before the "|stats values(field1)...." , put another stats command "|stats count by field1,field2". This should improve the performance.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2014 15:37:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130902#M35684</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-04-14T15:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130903#M35685</link>
      <description>&lt;P&gt;Yes you were right it improved the speed of that search a lot but for me there are no results now.&lt;BR /&gt;
The search look like this:&lt;/P&gt;

&lt;P&gt;sourcetype=zep-log OR sourcetype=otrs-log&lt;BR /&gt;
|stats count by field1,field2&lt;BR /&gt;
|stats values(field1) AS t1 values(field2) AS t2&lt;BR /&gt;
| mvexpand t1 &lt;BR /&gt;
| mvexpand t2&lt;BR /&gt;
| table t1 t2&lt;/P&gt;

&lt;P&gt;Like you see in this example i just wanted to table the results without any comparison of t1 and t2, but anyway there are no results. With removing one of the fields i get the right results! Like this:&lt;/P&gt;

&lt;P&gt;|stats count by field1&lt;BR /&gt;
|stats values(field1) AS t1&lt;BR /&gt;
|mvexpand t1&lt;BR /&gt;
|table t1&lt;/P&gt;

&lt;P&gt;Greetings&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 07:44:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130903#M35685</guid>
      <dc:creator>C_Sparn</dc:creator>
      <dc:date>2014-04-15T07:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130904#M35686</link>
      <description>&lt;P&gt;the problem is that with @somesoni2's first &lt;CODE&gt;stats&lt;/CODE&gt; you either have field1 or field2 in the event but not both. This will work if you change it to &lt;BR /&gt;
&lt;CODE&gt;| streamstats count by field1, field2&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Next, if don't want to compare fields you don't need to &lt;CODE&gt;mvexpand&lt;/CODE&gt; just use a &lt;CODE&gt;table&lt;/CODE&gt; and you're done. See this run everywhere example:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=_internal sourcetype="splunkd" OR sourcetype="splunk_web_access" | streamstats count by status, sourcePort, sourcetype | stats values(sourcePort) AS sourcePort, values(status) AS status, values(sourcetype) AS sourcetype | table status, sourcePort, sourcetype&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 08:26:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130904#M35686</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-15T08:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130905#M35687</link>
      <description>&lt;P&gt;Yes its true, streamstats is the solution. &lt;BR /&gt;
And with eval status = if(match(field2,field1),"","")&lt;BR /&gt;
it is working.&lt;BR /&gt;
I think now I understand what you want to say.&lt;BR /&gt;
I think for me this is working now:&lt;/P&gt;

&lt;P&gt;|streamstats count by field1, filed2 &lt;BR /&gt;
|stats values(field1) AS t1, values(field2) AS t2&lt;BR /&gt;&lt;BR /&gt;
|mvexpand t2 &lt;BR /&gt;
|where t2!=t1&lt;BR /&gt;
|table t2&lt;BR /&gt;
Thx for help&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 09:12:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130905#M35687</guid>
      <dc:creator>C_Sparn</dc:creator>
      <dc:date>2014-04-15T09:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130906#M35688</link>
      <description>&lt;P&gt;So now i checked out both possibilities and i noticed that it is exactly the same result for both methods:&lt;/P&gt;

&lt;P&gt;Method1:&lt;BR /&gt;
|mvexpand field2&lt;BR /&gt;
|eval status =if(match(field1,field2),"True","False")&lt;BR /&gt;
|where status ="False"&lt;/P&gt;

&lt;P&gt;Method2:&lt;BR /&gt;
|mvexpand field2&lt;BR /&gt;
|where field2!=field1&lt;/P&gt;

&lt;P&gt;But it works now. Thx!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 14:09:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130906#M35688</guid>
      <dc:creator>C_Sparn</dc:creator>
      <dc:date>2014-04-15T14:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130907#M35689</link>
      <description>&lt;P&gt;nice, feel free to accept the answer by ticking the tick. I will update the answer with the latest search command&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 14:11:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130907#M35689</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-15T14:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130908#M35690</link>
      <description>&lt;P&gt;Maybe before you can help me with another problem refering to that search. Is it possible to get all field values(in a table) of the events that have a value of the list i get with the search above?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 14:26:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130908#M35690</guid>
      <dc:creator>C_Sparn</dc:creator>
      <dc:date>2014-04-15T14:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130909#M35691</link>
      <description>&lt;P&gt;I have to split my comment because it will be too long......&lt;/P&gt;

&lt;P&gt;okay, listen this is my personal opinion: &lt;/P&gt;

&lt;P&gt;I will not answer this last question and I think it is pretty rude and not fair play after all, if you make it dependent to accept this answer only if I answer the next one.&lt;/P&gt;

&lt;P&gt;This is a community support page, although there are Splunk employees around and answering questions as well, most of us are Splunk users or Splunk Partners themselves and spent their spare time solving other people problems.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 19:18:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130909#M35691</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-15T19:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130910#M35692</link>
      <description>&lt;P&gt;You can show your support to this community by accepting a correct and useful answer and open a new question for your next problem.&lt;BR /&gt;
Also you could show some support to the people trying to help you, by up voting their answers or send some beers &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2014 19:18:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130910#M35692</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-15T19:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search that compares two lists of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130911#M35693</link>
      <description>&lt;P&gt;First I'm new to the splunk forum and didn't know how to vote for your very helpful answer.. so sorry! And besides I didn't want to vote just if you answer my next question, but I just thought that the new question is connected to the solved one, so I thought it's not necessary to open a new thread!!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Apr 2014 07:53:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-that-compares-two-lists-of-field-values/m-p/130911#M35693</guid>
      <dc:creator>C_Sparn</dc:creator>
      <dc:date>2014-04-16T07:53:02Z</dc:date>
    </item>
  </channel>
</rss>

