<?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 data from two indexes in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318041#M160057</link>
    <description>&lt;P&gt;i would try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=I earliest=-1d@d latest=now) OR (index=summary earliest=-1Y@Y latest=now)|stats values(importantFieldFromIndex1) values(importantFieldFromSummaryIndex) by Asset Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;since both have Asset and Date fields, you should be returned with a lot of data from either index shared by the two common fields.&lt;/P&gt;

&lt;P&gt;otherwise, if the join is the way you want to work it out, i'd try flipping them around, though i suggest trying to work through using the stats command, since join has limitations. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary ASSETNAME earliest=-1Y@Y latest=now|eval Asset1=Asset
|where isnull(Asset1)|stats count by Asset Date
|join type=left Asset Date [index=I earliest=-1d@d latest=now
|fields Asset Date ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 17 Jul 2017 17:55:23 GMT</pubDate>
    <dc:creator>cmerriman</dc:creator>
    <dc:date>2017-07-17T17:55:23Z</dc:date>
    <item>
      <title>How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318039#M160055</link>
      <description>&lt;P&gt;I want to get data from joining two indexes out of which one is summary index.&lt;BR /&gt;
Summary Index has more than 500000 records&lt;BR /&gt;
I have two fields Asset and Date in the summary index as well as in the other index.&lt;/P&gt;

&lt;P&gt;I am planning to schedule a query that will check for any new asset in today's records and if it is  a new, it will insert that record in the summary index.&lt;/P&gt;

&lt;P&gt;I tried to do it by leftjoin but it works if I specify a particular value for the Asset. &lt;/P&gt;

&lt;P&gt;Below is the query that works(ASSETNAME is the hard coded value) &lt;/P&gt;

&lt;P&gt;index=I ASSETNAME earliest=-1d@d latest=now&lt;BR /&gt;
|fields Asset Date&lt;BR /&gt;
|join type=left Combo(index=summary ASSETNAME earliest=-1Y@Y latest=now|eval Asset1=Asset&lt;BR /&gt;
|where isnull(Asset1)&lt;/P&gt;

&lt;P&gt;The same query does not work if I remove the asset name and run it with all the records in the Summary Index.&lt;/P&gt;

&lt;P&gt;It shows me null values in the column 'Asset1' for the assets that are there in the summary index.&lt;/P&gt;

&lt;P&gt;I am not sure if it is because of the the limit of the records a subsearch can return. &lt;BR /&gt;
Please suggest that if there is a better way of querying instead of using join.&lt;/P&gt;

&lt;P&gt;I tried to do it by this way also but it is not showing me complete set of records.&lt;/P&gt;

&lt;P&gt;(index=I earliest=-1d@d latest=now) OR (index=summary earliest=-1Y@Y latest=now)&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 17:23:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318039#M160055</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-17T17:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318040#M160056</link>
      <description>&lt;P&gt;try this&lt;/P&gt;

&lt;P&gt;1) (index=A OR index=B) rest of your query&lt;BR /&gt;
2) index=A  earliest=-1d@d latest=now | append [ search index=summary earliest=-1Y@Y latest=now] &lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 17:48:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318040#M160056</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-07-17T17:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318041#M160057</link>
      <description>&lt;P&gt;i would try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=I earliest=-1d@d latest=now) OR (index=summary earliest=-1Y@Y latest=now)|stats values(importantFieldFromIndex1) values(importantFieldFromSummaryIndex) by Asset Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;since both have Asset and Date fields, you should be returned with a lot of data from either index shared by the two common fields.&lt;/P&gt;

&lt;P&gt;otherwise, if the join is the way you want to work it out, i'd try flipping them around, though i suggest trying to work through using the stats command, since join has limitations. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary ASSETNAME earliest=-1Y@Y latest=now|eval Asset1=Asset
|where isnull(Asset1)|stats count by Asset Date
|join type=left Asset Date [index=I earliest=-1d@d latest=now
|fields Asset Date ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2017 17:55:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318041#M160057</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-17T17:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318042#M160058</link>
      <description>&lt;UL&gt;
&lt;LI&gt;&lt;P&gt;Always mark your code as code (the button marked 101 010 for example) so that the web interface doesn't&lt;BR /&gt;
strip out HTML-like constructs.  &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Your code as posted can't work, because the subsearch isn't in square braces.  &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;According to the posted code, you are left-joining on a field named Combo, and we can't see what that is.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;From your description, I don't know whether Date is a required part of the asset information, or whether Asset is a unique key.  The right answer depends on that.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;We don't know the format of the field Date. It may be significant to the solution.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Your final line as posted is correct.  (I'd suggest using latest=@d for the index=I, but that's quibbling.)  The next part after that is the processing that determines which ones need to be added.&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;This version assumes that Date1 is the Date field on the index=I record, that it is called Date2 on the summary record, and that Asset is a unique key regardless of the Date value.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=I Asset=* earliest=-1d@d latest=@d) OR (index=summary Asset=* earliest=-1Y@Y latest=now)
| eval NewDate = if(index=I, Date1, null())
| stats latest(NewDate) as Date2, count(eval(index="summary")) as SumExists by Asset
| where SumExists=0
| table Asset Date2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2017 18:27:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318042#M160058</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-17T18:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318043#M160059</link>
      <description>&lt;P&gt;am sorry for the mistake, I wrote just part of the query .&lt;/P&gt;

&lt;P&gt;Index=I has many other fields along with Asset and Date.&lt;/P&gt;

&lt;P&gt;I want to get the Earliest Date when that asset was tracked.&lt;/P&gt;

&lt;P&gt;Here is the query&lt;/P&gt;

&lt;P&gt;index=I  earliest=-1d@d latest=now&lt;BR /&gt;
|eval combo = Asset+"&lt;EM&gt;"+ID&lt;BR /&gt;
|stats min(First_Found_Date) as Earliest_FF by combo&lt;BR /&gt;
|join type=left combo[search index=summary  earliest=-1Y@Y latest=now|eval combo=Asset+"&lt;/EM&gt;"+ID|stats min(Earliest_FF) as Earliest_FF by combo|eval combo1=combo]&lt;/P&gt;

&lt;P&gt;|where isnull(combo1)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:57:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318043#M160059</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2020-09-29T14:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318044#M160060</link>
      <description>&lt;P&gt;Thanks for the reply. I tried it with append also but results are truncated to maxout of 50000.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 23:03:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318044#M160060</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-17T23:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318045#M160061</link>
      <description>&lt;P&gt;Thanks for the reply. &lt;BR /&gt;
Not sure why OR is not working for me. &lt;BR /&gt;
I tried this but it is not showing all the Assets.&lt;/P&gt;

&lt;P&gt;index=I earliest=-1d@d latest=now) OR (index=summary earliest=-1Y@Y latest=now)&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 23:06:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318045#M160061</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-17T23:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318046#M160062</link>
      <description>&lt;P&gt;Thanks for the reply. &lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 23:07:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318046#M160062</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-17T23:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318047#M160063</link>
      <description>&lt;P&gt;It will be great if anybody can help me understand why Or is not working for me. &lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 23:50:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318047#M160063</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-17T23:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318048#M160064</link>
      <description>&lt;P&gt;Try this and see what happens.  What type of data comes back?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=I earliest=-1d@d latest=now) OR (index=summary earliest=-1Y@Y latest=now)
|eval combo = Asset+""+ID|eval combo1=If(index="summary",combo,null())
|stats min(First_Found_Date) as FFD min(Earliest_FF) as EFF values(combo1) as combo1 by combo
|where isnull(combo1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jul 2017 00:53:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318048#M160064</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-18T00:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318049#M160065</link>
      <description>&lt;P&gt;If I am not wrong "OR" should return everything from the index=I as well as Index=summary.&lt;/P&gt;

&lt;P&gt;(index=qualys_summary earliest=-1Y@Y latest=now) returns 8000 Assets&lt;/P&gt;

&lt;P&gt;(index=I earliest=-1d@d latest=now) returns 6000 Assets&lt;/P&gt;

&lt;P&gt;(index=I earliest=-1d@d latest=now) OR (index=summary earliest=-1Y@Y latest=now) returns 2500 Assets from Index=I only&lt;/P&gt;

&lt;P&gt;Both the indexes have different fields. But Asset and Id is common to both.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 20:34:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318049#M160065</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-18T20:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318050#M160066</link>
      <description>&lt;P&gt;That part you posted is missing the initial open parenthesis.&lt;/P&gt;

&lt;P&gt;Hey, @cmerriman - If you could, please run a quick run-anywhere search to verify "earliest" can be used like that, with two different values inside different parenthesis?  I've never actually run something like that and I'm not at work today/ tomorrow so I can't test it.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 20:42:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318050#M160066</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-18T20:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318051#M160067</link>
      <description>&lt;P&gt;Thanks Dal Jeanis&lt;BR /&gt;
I have that initial open parenthesis in my query.&lt;BR /&gt;
(index=I earliest=-1d@d latest=now) OR (index=summary earliest=-1Y@Y latest=now)&lt;/P&gt;

&lt;P&gt;Actually I was also not sure when I posted this question if we can use earliest like that with two different values in two different parenthesis.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 20:59:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318051#M160067</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-18T20:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318052#M160068</link>
      <description>&lt;P&gt;I think we cant use earliest like that.&lt;BR /&gt;
I tried this query on the same index and  got today's results only.&lt;BR /&gt;
(index=I earliest=-3d@d latest=now) OR (index=I  earliest=-5d@d latest=now).&lt;/P&gt;

&lt;P&gt;Is there any other way to get data from two different indexes with different time frame and without using  join or append?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:11:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318052#M160068</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-18T21:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318053#M160069</link>
      <description>&lt;P&gt;i ran it with some of my own data using a &lt;CODE&gt;earliest=-30d@d latest=@d&lt;/CODE&gt; and &lt;CODE&gt;earliest=-1d@d latest=now&lt;/CODE&gt; and my events went from an average of 400 events/day to 100k yesterday, so i'd say it worked. i see both sourcetypes are coming through. @DalJeanis&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:13:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318053#M160069</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-18T21:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318054#M160070</link>
      <description>&lt;P&gt;are you using &lt;CODE&gt;index=qualys_summary&lt;/CODE&gt; or &lt;CODE&gt;index=summary&lt;/CODE&gt;? you have it listed both ways in your previous comment&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:14:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318054#M160070</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-18T21:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318055#M160071</link>
      <description>&lt;P&gt;I shows me both the sourcetypes if I use "append" but only one sourcetype if I use "OR"&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:18:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318055#M160071</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-18T21:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318056#M160072</link>
      <description>&lt;P&gt;Please ignore that. I am using summary for all my queries. Please ignore that mistake.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:22:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318056#M160072</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-18T21:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318057#M160073</link>
      <description>&lt;P&gt;So you are getting events for yesterday and today only and not 30 days?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:31:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318057#M160073</guid>
      <dc:creator>poojak2579</dc:creator>
      <dc:date>2017-07-18T21:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to join data from two indexes</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318058#M160074</link>
      <description>&lt;P&gt;I am getting events all 30 days for one of my events and only yesterday for the other. It seems to be working for me&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 22:19:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-data-from-two-indexes/m-p/318058#M160074</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-07-18T22:19:41Z</dc:date>
    </item>
  </channel>
</rss>

