<?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: Is there a way to extract/show the first and last events in a transaction? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218876#M64327</link>
    <description>&lt;P&gt;I get the issue here. What transaction does is creates a multivalued field for each available field in merged events and by default the multivalued field is create in the same way as &lt;CODE&gt;| stats values(field)&lt;/CODE&gt;, so basically they are sorted alphabetically and duplicate values are removed.  &lt;/P&gt;

&lt;P&gt;What you need to do is to use  &lt;CODE&gt;mvlist=t&lt;/CODE&gt; option in your transaction command and it'll retain the order of the field values (similar to &lt;CODE&gt;| stats list(field)&lt;/CODE&gt;), then the mvindex portion would work just fine. Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction query with mvlist=t | eval first_domain=mvindex(destination, 0) | eval last_domain=mvindex(destination, -1) | table user,first_domain,last_domain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;BR /&gt;
Try this for removing duplicates from user (or any field)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction query with mvlist=t | eval first_domain=mvindex(destination, 0) | eval last_domain=mvindex(destination, -1) | eval user=mvdedup(user) | table user,first_domain,last_domain
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Sep 2016 22:04:01 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-09-30T22:04:01Z</dc:date>
    <item>
      <title>Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218870#M64321</link>
      <description>&lt;P&gt;I have a transaction query that returns groups of logs that are typically 5-10 events clumped together.  The query uses startswith/endswith.  I really only care about the first and last event.  Is there any way I can pull these out or at least pull out some of the data from a field in the first and a field in the last?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 20:51:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218870#M64321</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2016-09-30T20:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218871#M64322</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search with transaction | eval field_first=mvindex(field, 0) | eval field_last=mvindex(field, mvcount(field)-1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;*&lt;STRONG&gt;&lt;EM&gt;UPDATED&lt;/EM&gt;&lt;/STRONG&gt;*&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search | transaction query mvlist=t | eval field_first=mvindex(field, 0) | eval field_last=mvindex(field, -1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2016 20:53:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218871#M64322</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-30T20:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218872#M64323</link>
      <description>&lt;P&gt;I got it to give me the first website someone goes to, but I can't get it to give me the last.  There are 9 total events grouped together in my transaction test.  It's giving me:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;first_site=from_log 1 (excellent!)&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;last_site=from_log 3 (not the last one, log 9)&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eval first_site=mvindex(destination, 0) | eval last_site=mvindex(destination,     mvcount(dest_hostname)-1) | table first_site,last_site&lt;/CODE&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:12:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218872#M64323</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2020-09-29T11:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218873#M64324</link>
      <description>&lt;P&gt;You're using wrong field name in the mvcount function.  If fact you could just remove that function completely, using just -1 will select the last item.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval first_site=mvindex(destination, 0) | eval last_site=mvindex(destination,-1) | table first_site,last_site
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2016 21:23:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218873#M64324</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-30T21:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218874#M64325</link>
      <description>&lt;P&gt;Below is some sample data of my transaction query (9 events grouped together as one)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;9/25 12:00:01 alibaba.com jondoe
9/25 12:00:01 reddit.com jondoe
9/25 12:00:01 &lt;A href="https://community.splunk.com/www.gmail.com" target="test_blank"&gt;www.gmail.com&lt;/A&gt; jondoe
...
...
...
...
...
9/25 12:00:01 malware.com jondoe
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And here is my what I currently am getting&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;query&lt;/STRONG&gt;:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction query | eval first_domain=mvindex(destination, 0) | eval last_domain=mvindex(destination, -1) | table user,first_domain,last_domain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;query results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;user      first_domain      last_domain
jondoe    alibaba.com       &lt;A href="https://community.splunk.com/www.google.com" target="test_blank"&gt;www.google.com&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2016 21:39:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218874#M64325</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2016-09-30T21:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218875#M64326</link>
      <description>&lt;P&gt;I tried making the changes, but still getting the same thing.  Any idea?  I'm at a loss because it would seem to make sense but isn't.  I posted some sample data in the original post to better clarify the issue and show what is happening.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 21:40:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218875#M64326</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2016-09-30T21:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218876#M64327</link>
      <description>&lt;P&gt;I get the issue here. What transaction does is creates a multivalued field for each available field in merged events and by default the multivalued field is create in the same way as &lt;CODE&gt;| stats values(field)&lt;/CODE&gt;, so basically they are sorted alphabetically and duplicate values are removed.  &lt;/P&gt;

&lt;P&gt;What you need to do is to use  &lt;CODE&gt;mvlist=t&lt;/CODE&gt; option in your transaction command and it'll retain the order of the field values (similar to &lt;CODE&gt;| stats list(field)&lt;/CODE&gt;), then the mvindex portion would work just fine. Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction query with mvlist=t | eval first_domain=mvindex(destination, 0) | eval last_domain=mvindex(destination, -1) | table user,first_domain,last_domain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;BR /&gt;
Try this for removing duplicates from user (or any field)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction query with mvlist=t | eval first_domain=mvindex(destination, 0) | eval last_domain=mvindex(destination, -1) | eval user=mvdedup(user) | table user,first_domain,last_domain
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2016 22:04:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218876#M64327</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-30T22:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218877#M64328</link>
      <description>&lt;P&gt;I had been looking over the data and realized the alphabetical order as well right before you posted!  Using &lt;CODE&gt;mvlist=t&lt;/CODE&gt; it extracts the first and last exactly as intended!  One small hiccup is that it lists the user 9 times (once for each log?) in the table.  Any ideas on that?  This is still something I can accept as the first/last are the most important to me but cleaning it up would be 11/10!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;user    first_domain    last_domain
jondoe  alibaba.com     malware.com
jondoe    
jondoe    
jondoe    
jondoe    
jondoe    
jondoe    
jondoe    
jondoe    
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2016 22:15:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218877#M64328</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2016-09-30T22:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to extract/show the first and last events in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218878#M64329</link>
      <description>&lt;P&gt;That works!  I got it to work by using eval and grabbing the first user in the logs, but I think your dedup solution is cleaner.  I really appreciate all the help!!  I learned about the mv commands now and learned I still have a lot to learn regarding Splunk.  Thank you very much.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 22:29:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-extract-show-the-first-and-last-events-in-a/m-p/218878#M64329</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2016-09-30T22:29:12Z</dc:date>
    </item>
  </channel>
</rss>

