<?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: Help me with search query for my usecase in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303299#M91269</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval raw="1 2 3"
| makemv raw
| mvexpand raw
| eval TRANSACTION_ID=case(raw==1, "101", raw==2, "102", raw==3, 101)
| eval REQUEST_ID=case(raw==2, "101", raw==3, 105)
| rename raw AS _raw
| fields - _time

| rename COMMENT AS "Everything above fakes sample data; everything below shows a guess at a solution"

| eval COMBINED_ID = if(isnull(REQUEST_ID), TRANSACTION_ID, TRANSACTION_ID . " " . REQUEST_ID)
| makemv COMBINED_ID
| stats list(_raw) AS raws values(*) AS * BY COMBINED_ID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 28 Mar 2017 20:35:45 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-03-28T20:35:45Z</dc:date>
    <item>
      <title>Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303289#M91259</link>
      <description>&lt;P&gt;i have two id's lets say ID1 and ID2&lt;/P&gt;

&lt;P&gt;i want to use transaction command for both ID1 and ID2 in same query , please help me with this.l&lt;/P&gt;

&lt;P&gt;i have more than two events those events contains some id's  like&lt;/P&gt;

&lt;H2&gt;event 1&lt;/H2&gt;

&lt;P&gt;TRANSACTION_ID=101&lt;/P&gt;

&lt;H2&gt;event 2&lt;/H2&gt;

&lt;P&gt;REQUEST_ID=101  TRANSACTION_ID=102&lt;/P&gt;

&lt;H2&gt;event 3&lt;/H2&gt;

&lt;P&gt;TRANSACTION_ID=101  REQUEST_ID=105&lt;/P&gt;

&lt;P&gt;i want to combine all 3  events event1,event2 and event3  into single event by value 101.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:28:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303289#M91259</guid>
      <dc:creator>sravankaripe</dc:creator>
      <dc:date>2020-09-29T13:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303290#M91260</link>
      <description>&lt;P&gt;can you give a bit more detail in what you're trying to accomplish and data examples or fields?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 14:35:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303290#M91260</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-03-28T14:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303291#M91261</link>
      <description>&lt;P&gt;Without much information, I would say you can create a common fields using eval like &lt;CODE&gt;| eval commonID=coalesce(ID1,ID2)&lt;/CODE&gt; and use it in transaction. Again, transactions are expensive and there might be alternatives, so if  you add more information, we may be able to provide better suggestions.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 14:42:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303291#M91261</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-28T14:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303292#M91262</link>
      <description>&lt;P&gt;You should avoid the use of &lt;CODE&gt;transaction&lt;/CODE&gt; whenever possible. You have not given us much information to go on but maybe this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats values(*) AS * BY ID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2017 14:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303292#M91262</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-28T14:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303293#M91263</link>
      <description>&lt;P&gt;Are you combining the two transactions because you are linking the &lt;CODE&gt;TRANSACTION_ID&lt;/CODE&gt; from the first event to the &lt;CODE&gt;REQUEST_ID&lt;/CODE&gt; from the second?&lt;/P&gt;

&lt;P&gt;If so, are you trying to also connect up a third transaction like this if it exists  &lt;CODE&gt;REQUEST_ID=102 TRANSACTION_ID=105&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;What are the actual data fields involved that you will be working with?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 15:07:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303293#M91263</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-28T15:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303294#M91264</link>
      <description>&lt;P&gt;i want to connect both by value 101&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 15:08:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303294#M91264</guid>
      <dc:creator>sravankaripe</dc:creator>
      <dc:date>2017-03-28T15:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303295#M91265</link>
      <description>&lt;P&gt;and combine both&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 15:08:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303295#M91265</guid>
      <dc:creator>sravankaripe</dc:creator>
      <dc:date>2017-03-28T15:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303296#M91266</link>
      <description>&lt;P&gt;You should be able to combine all three events using something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
| eval ID=split(coalesce(REQUEST_ID,"#")."#".TRANSACTION_ID,"#")
| mvexpand ID
| stats values(fieldthatyouwant1) as fieldthatyouwant1... by ID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2017 15:37:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303296#M91266</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-28T15:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303297#M91267</link>
      <description>&lt;P&gt;I'm making an assumption here that the sourcetype is always distinct in all 3 of your event examples.  For example that "event 2" is always of sourcetype "sourcetype2".  And event1 is sourcetype1 etc. If that assumption isn't true but is true of some other field, you'll have to modify this example a bit. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search terms&amp;gt;
| eval normalizedId=if(sourcetype="sourcetype2",REQUEST_ID,TRANSACTION_ID)
| fields normalizedId, TRANSACTION_ID someField anotherField yetAnotherField
| stats list(*) as * by normalizedId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;what this will do,  is roll up all the fields that you see in the fields line,   by ID.  And for the ID it will pick the REQUEST_ID field value within event2,  but the TRANSACTION_ID value for all other events. &lt;/P&gt;

&lt;P&gt;some other quick best practice notes: &lt;BR /&gt;
  - Avoid doing list(&lt;EM&gt;) as * without something before to limit the fields.  Here i've used a fields clause, but anything that serves to limit the fields is fine.    Sending unconstrained lists into list(&lt;/EM&gt;) as * can blow up memory usage if there are tons of fields (100, 200), often for no gain. &lt;BR /&gt;
- If the conditional logic to normalize the id is more complex, you often have to switch to the case() function in eval instead of if()  The full list of functions in eval is here - &lt;A href="https://docs.splunk.com/Documentation/Splunk/6.5.2/SearchReference/CommonEvalFunctions" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/6.5.2/SearchReference/CommonEvalFunctions&lt;/A&gt;  it's worth at least skimming and bookmarking. &lt;BR /&gt;
- transaction is probably not the way to go.  For one thing it breaks map reduce (forcing all event rows to come back to the search head), for another it'll be slower, However if you really feel like you want to see the raw event text,  note you can do &lt;CODE&gt;list(_raw) as _raw.   You may want to sneak a&lt;/CODE&gt;reverse&lt;CODE&gt;command in before the stats if so to reorder the lines earliest first.  (The astute reader will notice that&lt;/CODE&gt;list(_raw) as _raw` effectively brings back all the rows to the search head too. )&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:28:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303297#M91267</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2020-09-29T13:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303298#M91268</link>
      <description>&lt;P&gt;Maybe like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval ID=coalesce(ID1, ID2) | stats values(*) AS * BY ID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2017 15:39:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303298#M91268</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-28T15:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with search query for my usecase</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303299#M91269</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval raw="1 2 3"
| makemv raw
| mvexpand raw
| eval TRANSACTION_ID=case(raw==1, "101", raw==2, "102", raw==3, 101)
| eval REQUEST_ID=case(raw==2, "101", raw==3, 105)
| rename raw AS _raw
| fields - _time

| rename COMMENT AS "Everything above fakes sample data; everything below shows a guess at a solution"

| eval COMBINED_ID = if(isnull(REQUEST_ID), TRANSACTION_ID, TRANSACTION_ID . " " . REQUEST_ID)
| makemv COMBINED_ID
| stats list(_raw) AS raws values(*) AS * BY COMBINED_ID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2017 20:35:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-search-query-for-my-usecase/m-p/303299#M91269</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-28T20:35:45Z</dc:date>
    </item>
  </channel>
</rss>

