<?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 join search results from two indexes based on multiple conditions in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700228#M237642</link>
    <description>&lt;P&gt;Could you provide some sample (dummy) events from both index?&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 14:32:15 GMT</pubDate>
    <dc:creator>tread_splunk</dc:creator>
    <dc:date>2024-09-26T14:32:15Z</dc:date>
    <item>
      <title>How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700206#M237637</link>
      <description>&lt;P&gt;I have 2 indexes - &lt;EM&gt;index_1&lt;/EM&gt; and &lt;EM&gt;index_2&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;index_1&lt;/EM&gt; has the following fields&lt;/P&gt;&lt;P&gt;index1Id&lt;/P&gt;&lt;P&gt;currEventId&lt;/P&gt;&lt;P&gt;prevEventId&lt;/P&gt;&lt;P&gt;&lt;EM&gt;index_2&lt;/EM&gt; has the following fields&lt;/P&gt;&lt;P&gt;index2Id&lt;/P&gt;&lt;P&gt;eventId&lt;/P&gt;&lt;P&gt;eventOrigin&lt;/P&gt;&lt;P&gt;&lt;EM&gt;currEventId&lt;/EM&gt; and &lt;EM&gt;prevEventId&amp;nbsp;&lt;/EM&gt; in &lt;EM&gt;index_1&amp;nbsp;&lt;/EM&gt;will have the same values as that of &lt;EM&gt;eventId&lt;/EM&gt; of &lt;EM&gt;index_2&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Now, I am trying to create the table of the following format&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20%"&gt;index1Id&lt;/TD&gt;&lt;TD width="20%"&gt;prevEventId&lt;/TD&gt;&lt;TD width="20%"&gt;prevEventOrigin&lt;/TD&gt;&lt;TD width="20%"&gt;currEventId&lt;/TD&gt;&lt;TD width="20%"&gt;currEventOrigin&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the joins with the below query, but I see that the columns 3 and 5 are mostly blank. So, I am not sure what is wrong with the query.&lt;/P&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;&lt;LI-CODE lang="markup"&gt;index="index_1"
| join type=left currEventId 
    [ search index="index_2" 
     | rename eventId as currEventId, eventOrigin as currEventOrigin 
     | fields currEventId, currEventOrigin]
| join type=left prevEventId 
    [ search index="index_2" 
     | rename eventId as prevEventId, eventOrigin as prevEventOrigin 
     | fields prevEventId, prevEventOrigin]
| table index1Id, prevEventOrigin, currEventOrigin, prevEventId, currEventId&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And based on the online suggestions, I am trying the following approach, but couldn't complete it (works fine by populating all the columns)&lt;/P&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;&lt;LI-CODE lang="markup"&gt;(index="index_1") OR (index="index_2") | eval joiner=if(index="index_1", prevEventId, eventId) | stats values(*) as * by joiner 
|  where prevEventId=eventId | rename eventOrigin AS previousEventOrigin, eventId as previousEventId 
|  table index1Id, previousEventId, previousEventOrigin&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know an efficient way to achieve the solution. Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 12:32:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700206#M237637</guid>
      <dc:creator>ravi_lookout</dc:creator>
      <dc:date>2024-09-26T12:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700214#M237639</link>
      <description>&lt;P&gt;1. I'm not sure what you mean by "&lt;EM&gt;currEventId&lt;/EM&gt; and &lt;EM&gt;prevEventId&amp;nbsp;&lt;/EM&gt; in &lt;EM&gt;index_1&amp;nbsp;&lt;/EM&gt;will have the same values as that of &lt;EM&gt;eventId&lt;/EM&gt; of &lt;EM&gt;index_2&lt;/EM&gt;". Reading it literally it would mean that currEventId and prevEventId have the same value. So you can use just one of those fields, right?&lt;/P&gt;&lt;P&gt;2. Your stats-based idea looks pretty sound but:&lt;/P&gt;&lt;P&gt;- You use values(*) as * when you only use some of them. If you have many fields it's good to list them explicitly so you don't waste memory on storing fields you'll discard without using them&lt;/P&gt;&lt;P&gt;- I'm not sure what the part after the stats command is supposed to do. OK the "where" command may only leave the results "matching&amp;nbsp; both sides of the join". But the rename/table? Rename just for the sake of it? Are you sure you have a field called index1Id?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 12:55:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700214#M237639</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-26T12:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700228#M237642</link>
      <description>&lt;P&gt;Could you provide some sample (dummy) events from both index?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 14:32:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700228#M237642</guid>
      <dc:creator>tread_splunk</dc:creator>
      <dc:date>2024-09-26T14:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700245#M237645</link>
      <description>&lt;P&gt;Sample form index_1&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
 "index1Id": "Id_1",
 "currEventId": "EventId_1",
 "prevEventId": "EventId_2"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EventId_1 from index_2&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
 "eventId": "EventId_1",
 "eventOrigin": "EventOrigin_1",
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EventId_2 from index_2&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
 "eventId": "EventId_2",
 "eventOrigin": "EventOrigin_2",
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final result I am looking for, after the search&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20%" height="24px"&gt;index1Id&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;prevEventId&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;prevEventOrigin&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;currEventId&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;currEventOrigin&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="24px"&gt;Id_1&lt;/TD&gt;&lt;TD height="24px"&gt;EventId_2&lt;/TD&gt;&lt;TD height="24px"&gt;EventOrigin_2&lt;/TD&gt;&lt;TD height="24px"&gt;EventId_1&lt;/TD&gt;&lt;TD height="24px"&gt;EventOrigin_1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/148334"&gt;@tread_splunk&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 15:49:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700245#M237645</guid>
      <dc:creator>ravi_lookout</dc:creator>
      <dc:date>2024-09-26T15:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700246#M237646</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;, thanks for responding.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1. I just posted a sample for each of the indexes as a reply to Tred_splunk's question. Can you please check and see if that makes it clear? -&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700245/highlight/true#M237645" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700245/highlight/true#M237645&lt;/A&gt;&lt;/P&gt;&lt;P&gt;2. stats based search is good and I will consider your suggestion of adding only the necessary fields. However, this query is incomplete (in the sense that I am able to correlate only 1 event from index_2 to index_1 but not the other event)&lt;/P&gt;&lt;P&gt;3. The initial thought of renaming was to provide the distinction between two events from the same index (index_2) by identifying them as "current" and "previous"&lt;/P&gt;&lt;P&gt;I hope I was able to clarify.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 15:54:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700246#M237646</guid>
      <dc:creator>ravi_lookout</dc:creator>
      <dc:date>2024-09-26T15:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700271#M237655</link>
      <description>&lt;P&gt;Ahhh... So you don't want to just join two indexes. You want to join an index onto itself using external "bracketing" event.&lt;/P&gt;&lt;P&gt;Ugh.&lt;/P&gt;&lt;P&gt;With small datasets you can try to stats once then append the index again and stats another time. Well, you could even try to use the cursed join command &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But the real question is how to do this operation effectively. I have a rough idea but have to test it first.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 21:01:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700271#M237655</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-26T21:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700320#M237661</link>
      <description>&lt;P&gt;OK. Got it.&lt;/P&gt;&lt;P&gt;A run-anywhere search including mockup data&lt;/P&gt;&lt;PRE&gt;| makeresults format=csv data="index,index1Id,curEventId,prevEventId,eventId,eventOrigin&lt;BR /&gt;index1,23,11,13,,&lt;BR /&gt;index1,34,12,14,,&lt;BR /&gt;index1,35,12,16,,&lt;BR /&gt;index1,65,17,11,,&lt;BR /&gt;index1,88,15,12,,&lt;BR /&gt;index2,,,,11,1&lt;BR /&gt;index2,,,,12,2&lt;BR /&gt;index2,,,,13,3&lt;BR /&gt;index2,,,,14,4&lt;BR /&gt;index2,,,,15,5&lt;BR /&gt;index2,,,,16,6&lt;BR /&gt;index2,,,,17,7"&lt;BR /&gt;```This is just a mockup data preparation; now the fun begins```&lt;BR /&gt;```We make two EventId fields from our original one (we can't use rename because we don't want&lt;BR /&gt;to overwrite the values in the "joining" events with null values```&lt;BR /&gt;| eval curEventId=if(index="index1",curEventId,eventId)&lt;BR /&gt;| eval prevEventId=if(index="index1",prevEventId,eventId)&lt;BR /&gt;```And now we "copy over" the values from "single side" results into the compound "both sides" result```&lt;BR /&gt;```Be cautious about streamstats limitations```&lt;BR /&gt;| sort - index&lt;BR /&gt;| fields - index&lt;BR /&gt;| streamstats values(eventOrigin) AS curEventOrigin by curEventId&lt;BR /&gt;| streamstats values(eventOrigin) AS prevEventOrigin by prevEventId&lt;BR /&gt;```We only need the combined results, not the partial ones```&lt;BR /&gt;| where isnotnull(index1Id)&lt;BR /&gt;```clear empty fields```&lt;BR /&gt;| fields - eventId eventOrigin&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 08:38:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700320#M237661</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-27T08:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700332#M237665</link>
      <description>&lt;P&gt;Nice work&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;!&amp;nbsp; Imaginative approach!!&amp;nbsp; I tried out your solution and it appears to work if you replace &lt;EM&gt;streamstats&lt;/EM&gt; with &lt;EM&gt;eventstats.&amp;nbsp;&amp;nbsp;&lt;/EM&gt;Feels like that should work to me and eventstats feels more efficient than streamstats.&amp;nbsp; Any thoughts?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 11:05:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700332#M237665</guid>
      <dc:creator>tread_splunk</dc:creator>
      <dc:date>2024-09-27T11:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700333#M237666</link>
      <description>&lt;P&gt;Eventstats should work as well (streamstats relies obviously on the order of results that's why I'm sorting on index so that the "payload" events are before the "joining" events; if your indexes are named differently, you need to adjust this sort). Both commands have their own limitations and it will probably depend on particular use case which approach is more effective.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 11:10:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700333#M237666</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-27T11:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700518#M237694</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;, sorry I am not sure I fully understand. May I know where are we using the index_2 at all in the query?&lt;BR /&gt;Also, if I have to form the dummy data, would I not rather have two CSVs - one for the index_1 data and the other for index_2 data?&lt;/P&gt;&lt;P&gt;Btw, I tried to run the query, I am not getting the data in the tabular format. Adding this - &lt;EM&gt;table index1Id, curEventOrigin, curEventId, prevEventOrigin, prevEventId&lt;/EM&gt; to the end of your query didn't help.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 10:54:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700518#M237694</guid>
      <dc:creator>ravi_lookout</dc:creator>
      <dc:date>2024-09-30T10:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to join search results from two indexes based on multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700527#M237695</link>
      <description>&lt;P&gt;The mockup data contains events from both index1 and index2 (the first column of the dummy data).&lt;/P&gt;&lt;P&gt;It is assumed to be an equivalent of searching over (index=index1 OR index=index2).&lt;/P&gt;&lt;P&gt;Did you copy-paste my example search raw or did you modify it? And which Splunk version are you using?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 11:51:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-search-results-from-two-indexes-based-on-multiple/m-p/700527#M237695</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-30T11:51:44Z</dc:date>
    </item>
  </channel>
</rss>

