<?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 Combine 2 indexes with join based on result of a substring search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212946#M62399</link>
    <description>&lt;P&gt;I have 2 indexes:&lt;BR /&gt;
First index:&lt;BR /&gt;
index= abc with field1 having values like  "\A,\B,\C" and "\A,\D" and so on&lt;BR /&gt;
Second index:&lt;BR /&gt;
index=def with field 2 having values like A, F and so on.&lt;/P&gt;

&lt;P&gt;Now I have to join the 2 indexes using field1 and field2 such that &lt;BR /&gt;
 1.Search field1 of index abc for the value of field2  in index def (For instance a match happens when A in field2 is same as \A in field1)&lt;BR /&gt;
 2. When a match happens i need to combine these 2 rows using a join&lt;/P&gt;

&lt;P&gt;Can anyone please provide me guidance on how to approach this&lt;/P&gt;</description>
    <pubDate>Fri, 19 Feb 2016 17:29:13 GMT</pubDate>
    <dc:creator>diliptmonson</dc:creator>
    <dc:date>2016-02-19T17:29:13Z</dc:date>
    <item>
      <title>Combine 2 indexes with join based on result of a substring search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212946#M62399</link>
      <description>&lt;P&gt;I have 2 indexes:&lt;BR /&gt;
First index:&lt;BR /&gt;
index= abc with field1 having values like  "\A,\B,\C" and "\A,\D" and so on&lt;BR /&gt;
Second index:&lt;BR /&gt;
index=def with field 2 having values like A, F and so on.&lt;/P&gt;

&lt;P&gt;Now I have to join the 2 indexes using field1 and field2 such that &lt;BR /&gt;
 1.Search field1 of index abc for the value of field2  in index def (For instance a match happens when A in field2 is same as \A in field1)&lt;BR /&gt;
 2. When a match happens i need to combine these 2 rows using a join&lt;/P&gt;

&lt;P&gt;Can anyone please provide me guidance on how to approach this&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 17:29:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212946#M62399</guid>
      <dc:creator>diliptmonson</dc:creator>
      <dc:date>2016-02-19T17:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 indexes with join based on result of a substring search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212947#M62400</link>
      <description>&lt;P&gt;What all fields you want to join? Could you provide the fields from both indexes that you need in final output?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 17:40:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212947#M62400</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-02-19T17:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 indexes with join based on result of a substring search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212948#M62401</link>
      <description>&lt;P&gt;Hi Somesoni2,&lt;BR /&gt;
These are the 2 indexes I need to combine:&lt;/P&gt;

&lt;P&gt;index= abc; &lt;BR /&gt;
field1 - "\A,\B,\C";"\D,\E";"\F"&lt;BR /&gt;
field2 - Def, Ghj, Klm&lt;BR /&gt;
field3- Dpx,Abc, &lt;/P&gt;

&lt;P&gt;index=def;&lt;BR /&gt;
field4= "A","D","A"&lt;BR /&gt;
field5=123,245, 571&lt;/P&gt;

&lt;P&gt;Now I need to combine both these indexes together such that the result obtained is&lt;BR /&gt;
Row 1: "\A,\B,\C",Def,Dpx,"A",123 &lt;BR /&gt;
Row2: "\D,\E";"\F",Ghj,Abc, &lt;BR /&gt;
Row3:"\A,\B,\C",Def,Dpx,"A",571&lt;/P&gt;

&lt;P&gt;Thanks a lot for your help... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 18:52:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212948#M62401</guid>
      <dc:creator>diliptmonson</dc:creator>
      <dc:date>2016-02-19T18:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 indexes with join based on result of a substring search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212949#M62402</link>
      <description>&lt;P&gt;Not sure how efficient it'll be, but try something like this (this is assuming you've field4 single valued field (just one value) and field1 multivalued field OR contains multiple values.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc OR index=def   | eval commonfield=coalesce(field1,field4) | makemv commonfield delim="," | mvexpand commonfield | stats list(*) as * by commonfield | where isnotnull(field4) | eval temp=mvzip(field4,field5,"#") | mvexpand temp | rex field=temp "(?&amp;lt;field4&amp;gt;.*)#(?&amp;lt;field5&amp;gt;.*)"  | fields - temp commonfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See this run anywhere sample with your example data.(first 3 rows are just to generate data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval temp="A,B,C Def Dpx;D,E Ghi Abc;F Ghi " | table temp| makemv temp delim=";" | mvexpand temp | rex field=temp "(?&amp;lt;field1&amp;gt;.*)\s(?&amp;lt;field2&amp;gt;.*)\s(?&amp;lt;field3&amp;gt;.*)" | append [| gentimes start=-1 | eval temp="A 123;D 245;A 343" | table temp| makemv temp delim=";" | mvexpand temp | rex field=temp "(?&amp;lt;field4&amp;gt;.*)\s(?&amp;lt;field5&amp;gt;.*)" ] | fields - temp 
| eval commonfield=coalesce(field1,field4) | makemv commonfield delim="," | mvexpand commonfield | stats list(*) as * by commonfield | where isnotnull(field4) | eval temp=mvzip(field4,field5,"#") | mvexpand temp | rex field=temp "(?&amp;lt;field4&amp;gt;.*)#(?&amp;lt;field5&amp;gt;.*)"  | fields - temp commonfield
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Feb 2016 19:17:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-2-indexes-with-join-based-on-result-of-a-substring/m-p/212949#M62402</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-02-19T19:17:47Z</dc:date>
    </item>
  </channel>
</rss>

