<?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: Comparing every elements in a list with a table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667876#M229141</link>
    <description>&lt;P&gt;Rather than using json_extract(), try using spath&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=output1 path="data.affected_items{}.id{}" output=output3
| mvexpand output3
| table output3&lt;/LI-CODE&gt;&lt;P&gt;The mvexpand will split the output3 field across multiple events.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2023 12:55:43 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-11-08T12:55:43Z</dc:date>
    <item>
      <title>Comparing every elements in a list with a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667862#M229138</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;Could you advise, please, how can I compare results of 2 searches, which returns results in a different format?&lt;/P&gt;
&lt;P&gt;First search:&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;lt;first part of the search&amp;gt;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| eval output3 = json_extract(output1, "data.affected_items{}.id")
| table output3&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result of this search looks like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;["112","114","267","456"] (ony one row)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Second search:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;lt;first part of the search&amp;gt;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| table id&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result of this search looks like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id (header)&lt;/P&gt;
&lt;P&gt;111 (first row)&lt;/P&gt;
&lt;P&gt;112 (second row)&lt;/P&gt;
&lt;P&gt;255 (third row)&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The number of elements in results of the first and the second searches is different.&lt;BR /&gt;I need to combine this searches in the one search that will have in the result common elements in both searches.&lt;/P&gt;
&lt;P&gt;For example, if the first search has the following output:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;["112","114","267","456"]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And the second search has the following output:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;id (header)&lt;/P&gt;
&lt;P&gt;111 (first row)&lt;/P&gt;
&lt;P&gt;112 (second row)&lt;/P&gt;
&lt;P&gt;255 (third row)&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I need to have the following result:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id (header)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;112 (first row)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which Splunk functions or tools could you recommend for this purpose? The Splunk version is 8, so some new functionality from version 9 does not work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 13:10:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667862#M229138</guid>
      <dc:creator>oleg90</dc:creator>
      <dc:date>2023-11-08T13:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing every elements in a list with a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667876#M229141</link>
      <description>&lt;P&gt;Rather than using json_extract(), try using spath&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input=output1 path="data.affected_items{}.id{}" output=output3
| mvexpand output3
| table output3&lt;/LI-CODE&gt;&lt;P&gt;The mvexpand will split the output3 field across multiple events.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 12:55:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667876#M229141</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-11-08T12:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing every elements in a list with a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667878#M229143</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|eval output3 = replace(output3,"[\[\]\"]","")
|makemv output3 delim=","
|mvexpand output3
|rename output3 as id
|join id
[&amp;lt;second_search&amp;gt;]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to keep the original values of id from the first search add a temporary field:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|eval temp = replace(output3,"[\[\]\"]","")
|makemv temp_id delim=","
|mvexpand temp_id
|rename temp_id as id
|join id
[&amp;lt;second_search&amp;gt;]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to combine the results of the second query back together add this to the end:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| mvcombine id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep in mind that join only works with up to 50.000 events but it doesn't seem like this limitation is relevant to your situation based on the example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the second search is a static list of codes that you want to match you could also put the results of the second query in to a lookup table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|eval temp = replace(output3,"[\[\]\"]","")
|makemv temp_id delim=","
|mvexpand temp_id
|rename temp_id as id
|lookup &amp;lt;lookup_name&amp;gt; id OUTPUT id as found
|where isnotnull(found)
|fields - found&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 13:07:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667878#M229143</guid>
      <dc:creator>FelixLeh</dc:creator>
      <dc:date>2023-11-08T13:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing every elements in a list with a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667919#M229160</link>
      <description>&lt;P&gt;Thank you, but it doesn't work by some reason...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;| eval output1=json(output)&lt;BR /&gt;| eval output3 = json_extract(output1, "data.affected_items{}.id")&lt;BR /&gt;| table output3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- works fine, but the result in the one row&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;| eval output1=json(output)&lt;BR /&gt;| spath input=output1 path="data.affected_items{}.id{}" output=output3&lt;BR /&gt;| mvexpand output3&lt;BR /&gt;| table output3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- shows "No results found."&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 16:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667919#M229160</guid>
      <dc:creator>oleg90</dc:creator>
      <dc:date>2023-11-08T16:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing every elements in a list with a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667921#M229161</link>
      <description>&lt;P&gt;Perhaps if you shared your actual raw unformatted events (anonymised as appropriate) in a code block to preserve any formatting there might be in the event, we might be able to suggest something that might work with your data.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 16:02:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667921#M229161</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-11-08T16:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing every elements in a list with a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667924#M229163</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;| eval output1=json(output)&lt;BR /&gt;| eval output3 = json_extract(output1, "data.affected_items{}.id")&lt;BR /&gt;| eval output3 = replace(output3,"[\[\]\"]","")&lt;BR /&gt;| makemv output3 delim=","&lt;BR /&gt;| mvexpand output3&lt;BR /&gt;| rename output3 as id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;returns all ids in a column, so it seems it is what I need for further processing of this data. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 16:07:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667924#M229163</guid>
      <dc:creator>oleg90</dc:creator>
      <dc:date>2023-11-08T16:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing every elements in a list with a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667925#M229164</link>
      <description>&lt;P&gt;Thank you very much, it seems the previous recommendation works for me.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 16:09:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-every-elements-in-a-list-with-a-table/m-p/667925#M229164</guid>
      <dc:creator>oleg90</dc:creator>
      <dc:date>2023-11-08T16:09:16Z</dc:date>
    </item>
  </channel>
</rss>

