<?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 How to split and filter transaction events? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-and-filter-transaction-events/m-p/269586#M81113</link>
    <description>&lt;P&gt;We have denormalized some JSON events into CSV.  The events themselves have simple fields (in the example data, &lt;EM&gt;id&lt;/EM&gt;), and two arrays of objects (in the example data, &lt;EM&gt;foos&lt;/EM&gt; and &lt;EM&gt;bars&lt;/EM&gt;), and so the CSV equivalent will have all top-level fields on each row, and then either the first object type or second populated, with the other left empty.  Below is 5 sample events in both CSV and JSON (sample events are highly truncated for brevity).&lt;BR /&gt;
&lt;STRONG&gt;JSON:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ "id":1, "foos":[ { "fooval":"a", "footype":"red" }, { "fooval":"b", "footype":"red" }, { "fooval":"a", "footype":"red" }, { "fooval":"a", "footype":"green" } ], "bars":[ { "barval":"x" }, { "barval":"y" } ] }
{ "id":2, "foos":[ { "fooval":"a", "footype":"red" }, { "fooval":"c", "footype":"red" } ], "bars":[ { "barval":"z" } ] }
{ "id":3, "foos":[ { "fooval":"c", "footype":"green" }, { "fooval":"d", "footype":"green" } ], "bars":[ { "barval":"y" } ] }
{ "id":4, "foos":[ { "fooval":"a", "footype":"red" }, { "fooval":"c", "footype":"red" } ], "bars":[ { "barval":"y" } ] }
{ "id":5, "foos":[ { "fooval":"d", "footype":"red" }, { "fooval":"d", "footype":"red" }, { "fooval":"d", "footype":"red" }, { "fooval":"d", "footype":"green" } ], "bars":[ { "barval":"y" } ] }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;CSV:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;id,fooval,footype,barval
1,a,red,
1,b,red,
1,a,red,
1,a,green,
1,,,x
1,,,y
2,a,red,
2,c,red,
2,,,z
3,c,green,
3,d,green,
3,,,y
4,a,red,
4,c,red,
4,,,y
5,d,red,
5,d,red,
5,d,red,
5,d,green,
5,,,y
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The type of questions that we're struggling with are ones where we need to filter by a value contained in one object array, and then do something else like count the values of the second object array.  So using this data, a question we would like to answer is: &lt;EM&gt;get the count of unique fooval's for all events where there is a barval of 'y', and where the foo object has a footype of 'red'&lt;/EM&gt;&lt;BR /&gt;
For our sample data the expected answer would be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fooval  count
   a      3
   b      1
   c      1
   d      3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;(a would match for id 1 twice and id 4 once, b once for id 1, c once for id 4, and d three times for id 5)&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Since we need to filter the search by barval, which is never present in any rows that have a foo object, we have attempted the solution using the transaction command.  A simple attempt to do so looks like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search | transaction id | search barval=y footype=red | top fooval
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, the result here &lt;EM&gt;(a:2, b:1, c:1, d:1)&lt;/EM&gt; is only a count of the transacted events where these fields exist, not a unique filterer count.&lt;BR /&gt;
What gets us much closer is when we use the transaction option mvlist=true&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=search_trouble sourcetype=search_trouble_csv | transaction id mvlist=true | search barval=y footype=red | top fooval | where fooval!="NULL"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However this now gives us (&lt;EM&gt;a:4, b:1, c:1, d:4&lt;/EM&gt;), which is because we're still counting the foo objects where footype=red.&lt;BR /&gt;
Ideally I think we'd want to split the transaction back into events and apply another filter on footype, although attempts at this have failed (we tried using mvraw=true as well).&lt;/P&gt;

&lt;P&gt;Any insights would be appreciated, thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 04 Feb 2016 20:33:32 GMT</pubDate>
    <dc:creator>kevin_telford</dc:creator>
    <dc:date>2016-02-04T20:33:32Z</dc:date>
    <item>
      <title>How to split and filter transaction events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-and-filter-transaction-events/m-p/269586#M81113</link>
      <description>&lt;P&gt;We have denormalized some JSON events into CSV.  The events themselves have simple fields (in the example data, &lt;EM&gt;id&lt;/EM&gt;), and two arrays of objects (in the example data, &lt;EM&gt;foos&lt;/EM&gt; and &lt;EM&gt;bars&lt;/EM&gt;), and so the CSV equivalent will have all top-level fields on each row, and then either the first object type or second populated, with the other left empty.  Below is 5 sample events in both CSV and JSON (sample events are highly truncated for brevity).&lt;BR /&gt;
&lt;STRONG&gt;JSON:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ "id":1, "foos":[ { "fooval":"a", "footype":"red" }, { "fooval":"b", "footype":"red" }, { "fooval":"a", "footype":"red" }, { "fooval":"a", "footype":"green" } ], "bars":[ { "barval":"x" }, { "barval":"y" } ] }
{ "id":2, "foos":[ { "fooval":"a", "footype":"red" }, { "fooval":"c", "footype":"red" } ], "bars":[ { "barval":"z" } ] }
{ "id":3, "foos":[ { "fooval":"c", "footype":"green" }, { "fooval":"d", "footype":"green" } ], "bars":[ { "barval":"y" } ] }
{ "id":4, "foos":[ { "fooval":"a", "footype":"red" }, { "fooval":"c", "footype":"red" } ], "bars":[ { "barval":"y" } ] }
{ "id":5, "foos":[ { "fooval":"d", "footype":"red" }, { "fooval":"d", "footype":"red" }, { "fooval":"d", "footype":"red" }, { "fooval":"d", "footype":"green" } ], "bars":[ { "barval":"y" } ] }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;CSV:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;id,fooval,footype,barval
1,a,red,
1,b,red,
1,a,red,
1,a,green,
1,,,x
1,,,y
2,a,red,
2,c,red,
2,,,z
3,c,green,
3,d,green,
3,,,y
4,a,red,
4,c,red,
4,,,y
5,d,red,
5,d,red,
5,d,red,
5,d,green,
5,,,y
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The type of questions that we're struggling with are ones where we need to filter by a value contained in one object array, and then do something else like count the values of the second object array.  So using this data, a question we would like to answer is: &lt;EM&gt;get the count of unique fooval's for all events where there is a barval of 'y', and where the foo object has a footype of 'red'&lt;/EM&gt;&lt;BR /&gt;
For our sample data the expected answer would be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fooval  count
   a      3
   b      1
   c      1
   d      3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;(a would match for id 1 twice and id 4 once, b once for id 1, c once for id 4, and d three times for id 5)&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Since we need to filter the search by barval, which is never present in any rows that have a foo object, we have attempted the solution using the transaction command.  A simple attempt to do so looks like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search | transaction id | search barval=y footype=red | top fooval
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, the result here &lt;EM&gt;(a:2, b:1, c:1, d:1)&lt;/EM&gt; is only a count of the transacted events where these fields exist, not a unique filterer count.&lt;BR /&gt;
What gets us much closer is when we use the transaction option mvlist=true&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=search_trouble sourcetype=search_trouble_csv | transaction id mvlist=true | search barval=y footype=red | top fooval | where fooval!="NULL"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However this now gives us (&lt;EM&gt;a:4, b:1, c:1, d:4&lt;/EM&gt;), which is because we're still counting the foo objects where footype=red.&lt;BR /&gt;
Ideally I think we'd want to split the transaction back into events and apply another filter on footype, although attempts at this have failed (we tried using mvraw=true as well).&lt;/P&gt;

&lt;P&gt;Any insights would be appreciated, thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2016 20:33:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-and-filter-transaction-events/m-p/269586#M81113</guid>
      <dc:creator>kevin_telford</dc:creator>
      <dc:date>2016-02-04T20:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to split and filter transaction events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-and-filter-transaction-events/m-p/269587#M81114</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;This is what I've done (simply replace my inputcsv with your "index=search_trouble sourcetype=search_trouble_csv")&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv mycsv.csv
| eval foovaltype = fooval . "::" . footype
| stats list(foovaltype) as foovaltype, list(barval) as barval by id
| mvexpand barval
| mvexpand foovaltype
| eval temp = split(foovaltype,"::") | eval fooval = mvindex(temp,0) | eval footype = mvindex(temp,1)
| fields - temp, foovaltype
| stats count by fooval
| search barval=y footype=red
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And the output is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fooval  count
a   3
b   1
c   1
d   3 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:40:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-and-filter-transaction-events/m-p/269587#M81114</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2020-09-29T08:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to split and filter transaction events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-and-filter-transaction-events/m-p/269588#M81115</link>
      <description>&lt;P&gt;Very cool, thank you.  I always forget about stats list.  I had to change the order of the last two commands and search then stats count, but otherwise works like a charm.  Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2016 17:43:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-and-filter-transaction-events/m-p/269588#M81115</guid>
      <dc:creator>kevin_telford</dc:creator>
      <dc:date>2016-02-05T17:43:47Z</dc:date>
    </item>
  </channel>
</rss>

