<?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 Map command - How to make different searches in different indexes ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/471642#M132695</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am currently trying to relate "front" logs to "back" logs depending on their sessionIds and their timestamps in order to understand the errors I am getting (putting face to face "front results" and "back results") .&lt;/P&gt;

&lt;P&gt;The logic "flow" is as follows : &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;I am looking for service A logs that returned a 400 http code ("front" logs, so I need to be within my first index : let's call it front_index)&lt;/LI&gt;
&lt;LI&gt;For each log (one log = one error that occured), I want to extract its timestamp and its sessionId&lt;/LI&gt;
&lt;LI&gt;For each row I am getting, I want to be able to look for "back" logs (which means I am switching to my second index : let's call it back_index) depending on the timestamp and the sessionId. Each "front" logs can have several "back" logs.&lt;/LI&gt;
&lt;LI&gt;Finally, I want to be able to print some details such as the timestamp, the sessionId, some detailed errorCode if present, count if relevant, etc... But that's not the point &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;If I am doing it manually, here are the two searches I am running :&lt;/P&gt;

&lt;P&gt;search 1 : &lt;BR /&gt;
&lt;PRE&gt;index=front_index sourcetype=access_combined "/url/of/my/service" http_response_code=400&lt;/PRE&gt;&lt;BR /&gt;
results 1 : list of log where I can manually extract the sessionId and the timestamp of each log I want to analyse&lt;/P&gt;

&lt;P&gt;search 2 : &lt;BR /&gt;
&lt;PRE&gt;index="back_index" ** **&lt;/PRE&gt;&lt;BR /&gt;
results 2 : I am getting different kind of logs that I manually read in order to extract the information I am looking for&lt;/P&gt;

&lt;P&gt;This work well, but on large amount data, it's just.. not the way it should be done &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;So here is what I tried in order to help me going faster : &lt;/P&gt;

&lt;P&gt;search 3 : &lt;BR /&gt;
&lt;PRE&gt;index=front_index sourcetype=access_combined "/url/of/my/service" http_response_code=400 | table hour, minute, sessionId &lt;BR /&gt;
| map search="search index=back_index $hour$:$minute$ $sessionId$ &lt;BR /&gt;
| table _timestamp, session, errorCode"&lt;/PRE&gt;&lt;BR /&gt;
expectation : I am expecting the first part to extract for each log found the hour, the minute and the sessionId in the front_index and it seems to be fine but then I want the second search to iterate on each row of the first one and to look for all the logs it can find in the back_index related to the timestamp (the minute is precise enough as my timestamps logs don't always perfectly match) and the sessionId. &lt;/P&gt;

&lt;P&gt;My issue seems to be that I can't change the index I am working on. Every data I retrieve are from the front_index even if I know the data I am looking for are there. A first step would be to get data from both indexes in the final list of events (or at least from the back_index as this is from there that I will get the details I want).&lt;BR /&gt;
And I can't figure why I can't do that. I tried to use wildcards in order to search in both indexes as their names are partially the same, but it does not seems to work.&lt;/P&gt;

&lt;P&gt;I tried to look the different subjects related to the map command, but I did not find what could help me (or I missed it) or worse, I totally misunderstood something about the command.&lt;BR /&gt;
The map command seems to be the right way to do what I am trying to do, but.. if there is a better/simpler way, I am also interested of course.&lt;/P&gt;

&lt;P&gt;Thanks for your help,&lt;/P&gt;

&lt;P&gt;b&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 05:37:47 GMT</pubDate>
    <dc:creator>bdfr49</dc:creator>
    <dc:date>2020-09-30T05:37:47Z</dc:date>
    <item>
      <title>Map command - How to make different searches in different indexes ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/471642#M132695</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am currently trying to relate "front" logs to "back" logs depending on their sessionIds and their timestamps in order to understand the errors I am getting (putting face to face "front results" and "back results") .&lt;/P&gt;

&lt;P&gt;The logic "flow" is as follows : &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;I am looking for service A logs that returned a 400 http code ("front" logs, so I need to be within my first index : let's call it front_index)&lt;/LI&gt;
&lt;LI&gt;For each log (one log = one error that occured), I want to extract its timestamp and its sessionId&lt;/LI&gt;
&lt;LI&gt;For each row I am getting, I want to be able to look for "back" logs (which means I am switching to my second index : let's call it back_index) depending on the timestamp and the sessionId. Each "front" logs can have several "back" logs.&lt;/LI&gt;
&lt;LI&gt;Finally, I want to be able to print some details such as the timestamp, the sessionId, some detailed errorCode if present, count if relevant, etc... But that's not the point &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;If I am doing it manually, here are the two searches I am running :&lt;/P&gt;

&lt;P&gt;search 1 : &lt;BR /&gt;
&lt;PRE&gt;index=front_index sourcetype=access_combined "/url/of/my/service" http_response_code=400&lt;/PRE&gt;&lt;BR /&gt;
results 1 : list of log where I can manually extract the sessionId and the timestamp of each log I want to analyse&lt;/P&gt;

&lt;P&gt;search 2 : &lt;BR /&gt;
&lt;PRE&gt;index="back_index" ** **&lt;/PRE&gt;&lt;BR /&gt;
results 2 : I am getting different kind of logs that I manually read in order to extract the information I am looking for&lt;/P&gt;

&lt;P&gt;This work well, but on large amount data, it's just.. not the way it should be done &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;So here is what I tried in order to help me going faster : &lt;/P&gt;

&lt;P&gt;search 3 : &lt;BR /&gt;
&lt;PRE&gt;index=front_index sourcetype=access_combined "/url/of/my/service" http_response_code=400 | table hour, minute, sessionId &lt;BR /&gt;
| map search="search index=back_index $hour$:$minute$ $sessionId$ &lt;BR /&gt;
| table _timestamp, session, errorCode"&lt;/PRE&gt;&lt;BR /&gt;
expectation : I am expecting the first part to extract for each log found the hour, the minute and the sessionId in the front_index and it seems to be fine but then I want the second search to iterate on each row of the first one and to look for all the logs it can find in the back_index related to the timestamp (the minute is precise enough as my timestamps logs don't always perfectly match) and the sessionId. &lt;/P&gt;

&lt;P&gt;My issue seems to be that I can't change the index I am working on. Every data I retrieve are from the front_index even if I know the data I am looking for are there. A first step would be to get data from both indexes in the final list of events (or at least from the back_index as this is from there that I will get the details I want).&lt;BR /&gt;
And I can't figure why I can't do that. I tried to use wildcards in order to search in both indexes as their names are partially the same, but it does not seems to work.&lt;/P&gt;

&lt;P&gt;I tried to look the different subjects related to the map command, but I did not find what could help me (or I missed it) or worse, I totally misunderstood something about the command.&lt;BR /&gt;
The map command seems to be the right way to do what I am trying to do, but.. if there is a better/simpler way, I am also interested of course.&lt;/P&gt;

&lt;P&gt;Thanks for your help,&lt;/P&gt;

&lt;P&gt;b&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:37:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/471642#M132695</guid>
      <dc:creator>bdfr49</dc:creator>
      <dc:date>2020-09-30T05:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Map command - How to make different searches in different indexes ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/471643#M132696</link>
      <description>&lt;P&gt;I suspect this is not the best use of &lt;CODE&gt;map&lt;/CODE&gt;.  For one, &lt;CODE&gt;map&lt;/CODE&gt; defaults to 100 iterations, which may not be enough.  Worse, however, is you may find yourself scanning a very large back_index up to 100 times.&lt;/P&gt;

&lt;P&gt;Try combining the two searches the Splunk way.  Assuming you have "hour", "minute", and "sessionId" fields in both indexes, this should do it.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=front_index sourcetype=access_combined "/url/of/my/service" http_response_code=400) OR index=back_index 
| stats values(*) as * by hour, minute, sessionId
| table _timestamp, session, errorCode
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jun 2020 18:18:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/471643#M132696</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-06-04T18:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Map command - How to make different searches in different indexes ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/503882#M140671</link>
      <description>&lt;P&gt;Thanks for your answer !&amp;nbsp;&lt;BR /&gt;I understand the map command is not the best way to do this, speaking of performances (did not thought that way while trying to build my request but I should have &lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;)&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But the query you gave me does not seem to return what I expect.&lt;BR /&gt;&lt;BR /&gt;The search I make on the "front_index" is supposed to give me the ID and the timestamp of each iteration I need to check on the "back_index". Following this idea, I am expecting to get (in my final table) only the logs that matched the ID and the timestamp which should lead to one, two or maybe three logs for each iteration.&lt;BR /&gt;But here, I am getting way more logs than expected. Some of them don't even match with what I can manually see on the front (so, it is out of "scope").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was expecting the following command to match front log with back logs depending on the parameters that follow (hour, minute, sessionId) but it does not seem to work like that :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats values(*) as * by hour, minute, sessionId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have I misunderstood the way this command works ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here, without using the &lt;EM&gt;table&lt;/EM&gt; command at the end, I am getting a table which has unrelated logs (back logs from 22h35m** while I have no front logs for this timestamp and the http code I am looking for).&lt;/P&gt;&lt;P&gt;In a simple word, I am trying to restrict my "back search" depending on what my "front search" returned me.&lt;/P&gt;&lt;P&gt;Again, thank you for your help.&lt;BR /&gt;I'll keep trying&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 08:47:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/503882#M140671</guid>
      <dc:creator>bdfr49</dc:creator>
      <dc:date>2020-06-11T08:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Map command - How to make different searches in different indexes ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/503943#M140684</link>
      <description>&lt;P&gt;Let's see if we can reduce the amount of excess events.&amp;nbsp; This modified query will only consider events that have a sessionId field.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=front_index sourcetype=access_combined "/url/of/my/service" http_response_code=400 sessionId=*) OR (index=back_index sessionId=*)
| stats values(*) as * by hour, minute, sessionId
| table _timestamp, session, errorCode&lt;/LI-CODE&gt;&lt;P&gt;If that's not enough, try adding '&lt;FONT face="courier new,courier"&gt;hour=* minute=*&lt;/FONT&gt;' to each phrase in the base query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 15:15:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/503943#M140684</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-06-11T15:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Map command - How to make different searches in different indexes ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/504459#M140804</link>
      <description>&lt;P&gt;One of the issue I have (and that was not explicit because, I did not thought about it until now,&amp;nbsp; sorry), is that my sessionId is clearly indexed on the front logs (ie : got sessionId=xxxxxxxxx) whereas it is not on the back logs (the sessionId is appearing aggregated to an other id and is not clearly indexed - the format of the log is, let's say, "perfectible")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Currently, I just a made a dashboard to "help" me thinking :&amp;nbsp;&lt;/P&gt;&lt;P&gt;1/ Extraction of the sessionIds related the 400 errors (and their hour, minute, second, ...)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="front_index" sourcetype=access_combined "/url/of/my/service" http_code=400 | table timestamp, hour, minute, second, sessionId&lt;/LI-CODE&gt;&lt;P&gt;So the results is as follow :&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20%" height="25px"&gt;timestamp&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;hour&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;minute&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;second&lt;/TD&gt;&lt;TD width="20%" height="25px"&gt;sessionId&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20%" height="42px"&gt;2020-06-19 18:21:53&lt;/TD&gt;&lt;TD width="20%" height="42px"&gt;18&lt;/TD&gt;&lt;TD width="20%" height="42px"&gt;21&lt;/TD&gt;&lt;TD width="20%" height="42px"&gt;53&lt;/TD&gt;&lt;TD width="20%" height="42px"&gt;sessionIdOfMySecondError&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20%" height="47px"&gt;2020-06-19 18:10:45&lt;/TD&gt;&lt;TD width="20%" height="47px"&gt;18&lt;/TD&gt;&lt;TD width="20%" height="47px"&gt;10&lt;/TD&gt;&lt;TD width="20%" height="47px"&gt;45&lt;/TD&gt;&lt;TD width="20%" height="47px"&gt;&amp;nbsp;sessionIdOfMyFirstError&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2/ As I click on one of the line of my previous search, I get to extract and re-use some values to identify the back logs that I want.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="back_index" *$sessionId$* *$hour$:$minute$:$second$* | where errorCode!="" | table timestamp, errorCode&lt;/LI-CODE&gt;&lt;P&gt;As the errorCode I want is not always there and is not properly indexed (again - I had to extract it with a regex), I use the "where" clause to exclude the events where it is missing.&lt;/P&gt;&lt;P&gt;So, if I am cliking on the first row of my first table :&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;timestamp&lt;/TD&gt;&lt;TD width="50%"&gt;errorCode&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;2020-06-19 18:10:45&lt;/TD&gt;&lt;TD width="50%"&gt;explicit_error_code&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the back log event I am interested in (there are some others with a different template, but, this the first one) :&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2020-06-19|18:21:53|ACH|someId_sessionId|ERROR|my.domain.error.mapper.GenericExceptionMapper|ServiceException contextualErrorCode=xxxx, reponse will be ErrorCode=explicit_error_code1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This works fine, but it forces me to "blindly" investigate each front log hoping for some helpful back logs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I would like in the end would be as follows :&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;timestamp&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;sessionId&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;errorCode&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-06-19 18:21:53&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;sessionIdOfMySecondError&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;explicit_error_code2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-06-19 18:10:45&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;sessionIdOfMyFirstError&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;explicit_error_code1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The map command looked ideal to get to this kind of results (not speaking of performance at all which must be taken into account of course)&amp;nbsp; whereas, using the "OR" clause with the stats command seemed to "just mix the events" (no matter the timestamp nor the sessionId) =&amp;gt; it does not seem to permit to build the table I want.&lt;/P&gt;&lt;P&gt;Don't get me wrong : I am not sure about that, maybe I am totally wrong &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought about using :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;subsearch&lt;/LI&gt;&lt;LI&gt;join&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;But they don't seem to be meant for this "loopy" logic I am thinking of (which may not be the best way to look at it, but I am struggling thinking in a different manner right now)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;BR /&gt;Hope I am not completely wrong about this (missing the point of your solutions :))&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 16:02:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Map-command-How-to-make-different-searches-in-different-indexes/m-p/504459#M140804</guid>
      <dc:creator>bdfr49</dc:creator>
      <dc:date>2020-06-15T16:02:57Z</dc:date>
    </item>
  </channel>
</rss>

