<?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: How to check if record exists in another index? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-record-exists-in-another-index/m-p/325019#M96942</link>
    <description>&lt;P&gt;hey try this run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval TicketNumber="2 3 4" 
| makemv TicketNumber 
| mvexpand TicketNumber 
| table TicketNumber 
| join type=outer TicketNumber 
    [| makeresults 
    | eval TicketNumber="1 2 3" 
    | makemv TicketNumber 
    | mvexpand TicketNumber 
    | table TicketNumber 
    | eval ExistingInTable1?="Yes"] 
| fillnull value="No"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your environment, you should try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;base table 2 search&amp;gt; 
| dedup TicketNumber 
| table TicketNumber 
| join type=outer TicketNumber 
    [ &amp;lt;base table 1 search&amp;gt; 
    | dedup TicketNumber 
    | table TicketNumber 
    | eval ExistingInTable1?="Yes"] 
| fillnull value="No"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Considering the performance factor, the best way to achieve this is&lt;/P&gt;

&lt;P&gt;suppose you have &lt;CODE&gt;table1 and table2 in different indexes or sources or sourcetypes&lt;/CODE&gt;&lt;BR /&gt;
I am not sure it will work or not but you can always give it a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=table1 OR index=table2  | stats dc(index) as dc values(eval(if(index="table2",1,0))) as table2 by TicketNumber  | search table2=1 | eval ExistingInTable1?=if(dc=2,"Yes","No") | table TicketNumber ExistingInTable1?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can choose source or sourcetype instead of index.&lt;BR /&gt;
let me know if this helps!&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2018 13:01:17 GMT</pubDate>
    <dc:creator>mayurr98</dc:creator>
    <dc:date>2018-02-28T13:01:17Z</dc:date>
    <item>
      <title>How to check if record exists in another index?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-record-exists-in-another-index/m-p/325018#M96941</link>
      <description>&lt;P&gt;I have two tables containing ticket numbers:&lt;/P&gt;

&lt;P&gt;table 1&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TicketNumber 
1             
2 
3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;table 2&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TicketNumber
2
3
4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I want to create a search using table2 but with an additional field if it exists in table1.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TicketNumber ExistingInTable1?
2             Yes
3             Yes
4             No
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Feb 2018 12:32:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-record-exists-in-another-index/m-p/325018#M96941</guid>
      <dc:creator>michaelrosello</dc:creator>
      <dc:date>2018-02-28T12:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if record exists in another index?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-record-exists-in-another-index/m-p/325019#M96942</link>
      <description>&lt;P&gt;hey try this run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval TicketNumber="2 3 4" 
| makemv TicketNumber 
| mvexpand TicketNumber 
| table TicketNumber 
| join type=outer TicketNumber 
    [| makeresults 
    | eval TicketNumber="1 2 3" 
    | makemv TicketNumber 
    | mvexpand TicketNumber 
    | table TicketNumber 
    | eval ExistingInTable1?="Yes"] 
| fillnull value="No"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In your environment, you should try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;base table 2 search&amp;gt; 
| dedup TicketNumber 
| table TicketNumber 
| join type=outer TicketNumber 
    [ &amp;lt;base table 1 search&amp;gt; 
    | dedup TicketNumber 
    | table TicketNumber 
    | eval ExistingInTable1?="Yes"] 
| fillnull value="No"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Considering the performance factor, the best way to achieve this is&lt;/P&gt;

&lt;P&gt;suppose you have &lt;CODE&gt;table1 and table2 in different indexes or sources or sourcetypes&lt;/CODE&gt;&lt;BR /&gt;
I am not sure it will work or not but you can always give it a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=table1 OR index=table2  | stats dc(index) as dc values(eval(if(index="table2",1,0))) as table2 by TicketNumber  | search table2=1 | eval ExistingInTable1?=if(dc=2,"Yes","No") | table TicketNumber ExistingInTable1?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can choose source or sourcetype instead of index.&lt;BR /&gt;
let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 13:01:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-record-exists-in-another-index/m-p/325019#M96942</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-02-28T13:01:17Z</dc:date>
    </item>
  </channel>
</rss>

