<?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 do I do search between 2 different indexes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382946#M111876</link>
    <description>&lt;P&gt;The best thing to do is to put the video details into a lookup file with a true-up scheduled search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=videoreport
| dedup videoid
| table duration videoid
| appendpipe [|inputlookup VideosAndDurations.csv]
| dedup videoid
| outputlookup VideosAndDurations.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then use it to lookup in the other search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index = viewerreport
| stats count BY videoid user
| lookup VideosAndDurations videoid OUTPUT duration
| eval video_total = duration * count
| stats sum(video_total) AS grand_total BY user
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 05 May 2018 18:15:33 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2018-05-05T18:15:33Z</dc:date>
    <item>
      <title>How do I do search between 2 different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382943#M111873</link>
      <description>&lt;P&gt;Think of this as a youtube scenario where I have 2 different indexes: viewerreport and videoreport.  The viewerreport contains a column videoId, which I could use this Id to search for an event/video from videoreport index. A video could be watch by any user 1, 2, 100 times vary. The videoreport contains a column duration. How can I calculate the total duration of all the videos that users viewed?&lt;BR /&gt;
Is this possible in splunk?&lt;/P&gt;

&lt;P&gt;I have been trying this for 2 days and still can not come up with an answer. I can't think of a better way of doing this than for loop but so far I tried inputlookup, which doesn't actually fit the case. Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Sat, 05 May 2018 08:18:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382943#M111873</guid>
      <dc:creator>tamduong16</dc:creator>
      <dc:date>2018-05-05T08:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I do search between 2 different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382944#M111874</link>
      <description>&lt;P&gt;Hi tamduong16,&lt;BR /&gt;
if you want so sum durations of all IDs (field named "Id") in videoreport index it's easy:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=videoreport
| stats sum(duration) AS Total_Duration BY Id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if instad you want to sum only IDs that are both in viewerreport and videoreport indexes, you could run this search&lt;BR /&gt;
( I define that Id is named "Id" In videoreport and "videoId" in viewerreport, otherwise you have to rename fields in the correct way)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=videoreport [ search index=viewerreport | rename videoId AS Id | dedup Id | fields Id ]
| stats sum(duration) AS Total_Duration BY Id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this way, you use the subsearch (viewerreport  index) to filter the main search (videoreport index) and then you can sum durations.&lt;/P&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Sat, 05 May 2018 08:59:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382944#M111874</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2018-05-05T08:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I do search between 2 different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382945#M111875</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|mulisearch
[ search index=videoreport
| dedup videoid
| table duration videoid ]

[ search index=viewerreport
| stats count BY videoid user
| eval user_count = user . "=" . count
| table user_count videoid ]

| stats values(*) AS * BY videoid
| mvexpand user_count
| rex field=user_count "^(?&amp;lt;user&amp;gt;[^=]+)=(?&amp;lt;count&amp;gt;[^=]+)$"
| eval video_total = duration * count
| stats sum(video_total) AS grand_total BY user
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 May 2018 15:56:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382945#M111875</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-05-05T15:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I do search between 2 different indexes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382946#M111876</link>
      <description>&lt;P&gt;The best thing to do is to put the video details into a lookup file with a true-up scheduled search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=videoreport
| dedup videoid
| table duration videoid
| appendpipe [|inputlookup VideosAndDurations.csv]
| dedup videoid
| outputlookup VideosAndDurations.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then use it to lookup in the other search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index = viewerreport
| stats count BY videoid user
| lookup VideosAndDurations videoid OUTPUT duration
| eval video_total = duration * count
| stats sum(video_total) AS grand_total BY user
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 May 2018 18:15:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-do-search-between-2-different-indexes/m-p/382946#M111876</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-05-05T18:15:33Z</dc:date>
    </item>
  </channel>
</rss>

