<?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: Flatten Search Results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362839#M107192</link>
    <description>&lt;P&gt;I tried this solution.&lt;BR /&gt;
But it looks like it only returns the first record not all of them.&lt;/P&gt;

&lt;P&gt;It should look like this:&lt;BR /&gt;
 "Order-no", "order-date", "price","quantity"&lt;BR /&gt;
 1        ,       20/05/2017        , 1.0, 1&lt;BR /&gt;
 1        ,       20/05/2017        , 2.0, 1&lt;BR /&gt;
 1        ,       20/05/2017        , 3.0, 2&lt;/P&gt;

&lt;P&gt;But instead it looks like this:&lt;BR /&gt;
 "Order-no", "order-date", "price","quantity"&lt;BR /&gt;
 1        ,       20/05/2017        , 1.0, 1&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2017 06:10:40 GMT</pubDate>
    <dc:creator>shinglau</dc:creator>
    <dc:date>2017-08-15T06:10:40Z</dc:date>
    <item>
      <title>Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362833#M107186</link>
      <description>&lt;P&gt;I am currently trying to use the Splunk REST API to extract a heap of data.&lt;BR /&gt;
I have written a search query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=* OR index=_*) (index="myindex") | table "order-no", "order-date", "price"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it provides a result set which looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"Order-no", "order-date", "price","quantity"
1        ,       20/05/2017        , 1.0, 1
--------------------, 2.0, 1
---------------------,3.0, 2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It rolls &lt;CODE&gt;2.0&lt;/CODE&gt; and &lt;CODE&gt;3.0&lt;/CODE&gt; up to 1 record along side row &lt;CODE&gt;order-no&lt;/CODE&gt; = &lt;CODE&gt;1&lt;/CODE&gt;.&lt;BR /&gt;
So when i try to export this as a CSV using REST API, the output is all jumbled up.&lt;/P&gt;

&lt;P&gt;Is there a way to flatten this in the search so it shows as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"Order-no", "order-date", "price","quantity"
1        ,       20/05/2017        , 1.0, 1
1        ,       20/05/2017        , 2.0, 1
1        ,       20/05/2017        , 3.0, 2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've tried to use &lt;CODE&gt;mvexpand&lt;/CODE&gt;, but it appears that it works on a individual column level and if i do a &lt;CODE&gt;mvexpand&lt;/CODE&gt; on both of those last 2 columns, it effectively does a cross join on the entire data which causes incorrect values&lt;BR /&gt;
Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 05:17:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362833#M107186</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-11T05:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362834#M107187</link>
      <description>&lt;P&gt;Assuming you have this format&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table order-no order-date price quantity
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and price and quantity are both multivalue fields that are aligned with each other, then do this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval price=mvzip(price,quantity,"@")
| mvexpand price
| eval price=split(price,"@")
| eval quantity=mvindex(price,1)
| eval price=mvindex(price,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you had a third field, which might contain an &lt;CODE&gt;@&lt;/CODE&gt; sign, and you don't have people entering enthusiastic comments, then I recommend five bangs as a delimiter &lt;CODE&gt;"!!!!!"&lt;/CODE&gt;.  You can also substitute any highly unlikely combination of characters ( &lt;CODE&gt;"!!#@#!!"&lt;/CODE&gt; ).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table order-no order-date price quantity description
| eval price=mvzip(mvzip(price,quantity,"!!!!!"),description,"!!!!!")
| mvexpand price
| eval price=split(price,"!!!!!")
| eval description=mvindex(price,2)
| eval quantity=mvindex(price,1)
| eval price=mvindex(price,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Aug 2017 14:50:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362834#M107187</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-11T14:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362835#M107188</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval orders="1.0,1:2.0,1:3.0,2"
| makemv delim=":" orders
| mvexpand orders
| rename orders AS _raw
| eval "Order-no" = 1
| rename _time AS "order-date"
| convert ctime(*date)
| rex "^(?&amp;lt;price&amp;gt;\S+),(?&amp;lt;quantity&amp;gt;\S+)$"
| fields - _raw
| stats list(*) AS * BY Order-no order-date

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| eval PsAndQs = mvzip(price,quantity)
| mvexpand PsAndQs
| rex field=PsAndQs "^(?&amp;lt;price&amp;gt;\S+),(?&amp;lt;quantity&amp;gt;\S+)$"
| fields - PsAndQs
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Aug 2017 23:00:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362835#M107188</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-11T23:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362836#M107189</link>
      <description>&lt;P&gt;I tried this solution but it keeps on giving me error:&lt;BR /&gt;
Error in 'eval' command: The arguments to the 'mvzip' function are invalid.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 02:55:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362836#M107189</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-15T02:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362837#M107190</link>
      <description>&lt;P&gt;Nevermind found out why..... Looks like eval doesn't like columns with "-" in it.&lt;BR /&gt;
Had to rename the column without a "-" then reference it in mvzip and it worked.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 03:32:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362837#M107190</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-15T03:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362838#M107191</link>
      <description>&lt;P&gt;Looks like using this solution only returns the first record, and doesn't return the other records within the group.&lt;/P&gt;

&lt;P&gt;Should look like:&lt;BR /&gt;
 "Order-no", "order-date", "price","quantity"&lt;BR /&gt;
 1        ,       20/05/2017        , 1.0, 1&lt;BR /&gt;
 1        ,       20/05/2017        , 2.0, 1&lt;BR /&gt;
 1        ,       20/05/2017        , 3.0, 2&lt;/P&gt;

&lt;P&gt;Instead it returns this:&lt;BR /&gt;
 "Order-no", "order-date", "price","quantity"&lt;BR /&gt;
 1        ,       20/05/2017        , 1.0, 1&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 06:09:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362838#M107191</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-15T06:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362839#M107192</link>
      <description>&lt;P&gt;I tried this solution.&lt;BR /&gt;
But it looks like it only returns the first record not all of them.&lt;/P&gt;

&lt;P&gt;It should look like this:&lt;BR /&gt;
 "Order-no", "order-date", "price","quantity"&lt;BR /&gt;
 1        ,       20/05/2017        , 1.0, 1&lt;BR /&gt;
 1        ,       20/05/2017        , 2.0, 1&lt;BR /&gt;
 1        ,       20/05/2017        , 3.0, 2&lt;/P&gt;

&lt;P&gt;But instead it looks like this:&lt;BR /&gt;
 "Order-no", "order-date", "price","quantity"&lt;BR /&gt;
 1        ,       20/05/2017        , 1.0, 1&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 06:10:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362839#M107192</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-15T06:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362840#M107193</link>
      <description>&lt;P&gt;Looks like when any of the columns within the mvzip is null / empty string, it drops the entire row. Anyway to fix this?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 12:00:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362840#M107193</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-15T12:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362841#M107194</link>
      <description>&lt;P&gt;Sure, give my answer a try.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 12:55:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362841#M107194</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-15T12:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362842#M107195</link>
      <description>&lt;P&gt;Interesting, even your answer drops it when one of the columns within your mvzip is empty.&lt;BR /&gt;
I think its because the multivalue field actually doesn't have a value for it, and doesn't know about the other columns. Even if i use a replace "" or fillnull on the original data, it doesn't fill the ones in MVs. Any idea how to fillnulls/replace "" in MV so it lines up with the data?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 23:02:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362842#M107195</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-15T23:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362843#M107196</link>
      <description>&lt;P&gt;This makes no sense.  How could a valid row or event ever have an undefined &lt;CODE&gt;price&lt;/CODE&gt; or an undefined &lt;CODE&gt;quantity&lt;/CODE&gt; and even if it did, who care if it is lost, it is totally invalid/nonsensical anyway.  Something &lt;EM&gt;really&lt;/EM&gt; doesn't add up here.  If you run the full run-anywhere example, there is no question: it works.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 23:21:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362843#M107196</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-15T23:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362844#M107197</link>
      <description>&lt;P&gt;Im adding a few more other MV columns which arent equal in rows. E.g. they may have nulls.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 23:37:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362844#M107197</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-15T23:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362845#M107198</link>
      <description>&lt;P&gt;Now see, that makes a H*U*G*E difference.  Just add &lt;CODE&gt;| fillnull value="NULL"&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:22:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362845#M107198</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-09-29T15:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362846#M107199</link>
      <description>&lt;P&gt;attempting to fillnull, but doesn't seem to do anything, still only showing the ones which are not null for all of the fields in mvzip.&lt;/P&gt;

&lt;P&gt;|fillnull value=NULL newfield&lt;BR /&gt;
| eval PsAndQs = mvzip(mvzip(price,quantity),newfield)&lt;BR /&gt;
 | mvexpand PsAndQs&lt;BR /&gt;
 | rex field=PsAndQs "^(?\S+),(?\S+),(?\S+)$"&lt;BR /&gt;
 | fields - PsAndQs&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 00:28:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362846#M107199</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-16T00:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362847#M107200</link>
      <description>&lt;P&gt;Just show us a REAL starting event with ALL of the fields (one that ends up broken).&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 01:44:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362847#M107200</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-16T01:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362848#M107201</link>
      <description>&lt;P&gt;@shinglau - These methods are not appropriate for fields that are not precisely matched, with the same number of mv fields.    If a field is supposed to be matched and is null, then you need to create a placeholder mv field, for example with the word "NULL" the correct number of times.  &lt;/P&gt;

&lt;P&gt;Assuming that the description may be null, the price and quantity are always matched and never null, and price and quantity can never appear more than 40 times, that could look something like... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | table order-no order-date price quantity description
 | eval mynulls=mvappend("((UNUSED))",
   "((NULL))","((NULL))","((NULL))","((NULL))","((NULL))", "((NULL))","((NULL))","((NULL))",
   "((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))",
   "((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))",
   "((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))",
   "((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))","((NULL))")
 | eval description=coalesce(description,mvindex(mynulls,1,mvcount(price)))
 | eval price=mvzip(mvzip(price,quantity,"!!!!!"),description,"!!!!!")
 | mvexpand price
 | eval price=split(price,"!!!!!")
 | eval description=mvindex(price,2)
 | eval description=if(description="((NULL))",null(),description)
 | eval quantity=mvindex(price,1)
 | eval price=mvindex(price,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If a field is not directly linked to the other fields (price, quantity, cost etc) then do not handle it in the same phase.  If it IS directly linked to the other fields but is for some reason not aligned, then it requires a separate question with specifics so that we can handle that error appropriately.  &lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 01:53:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362848#M107201</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-16T01:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362849#M107202</link>
      <description>&lt;P&gt;Input Table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;order-no    order-date  currency    country-code    quantity(MV)    base-price(MV)  net-price(MV)   product-id(MV)  customer-no adjust-coupon-id(MV)
1   2017-07-31T13:13:31.000Z    AUD AU  1.0 30.00   27.27   2   123 BFFYAY
                1.0 50.00   45.45   3       BFFYAY
                1.0 45.00   40.91   4       BFFYAY
                1.0 45.00   40.91   5       &amp;lt;NO VALUE&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Current Query to Flatten:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=* OR index=_*) (index="myindex" "order{@order-no}"="1" "order.customer.customer-no"="*")
| rename order{@order-no} as "order-no",
order.order-date as "order-date",
order.currency as "currency",
order.shipments.shipment.shipping-address.country-code as "country-code",
order.product-lineitems.product-lineitem.product-id as "productid",
order.product-lineitems.product-lineitem.quantity as "quantity",
order.product-lineitems.product-lineitem.base-price as "baseprice",
order.product-lineitems.product-lineitem.net-price as "netprice",
order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.promotion-id as "adjustpromotionid",
order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.campaign-id as "adjustcampaignid",
order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.coupon-id as "adjustcouponid",
order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.lineitem-text as "adjustlineitemtext",
order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.base-price as "adjustbaseprice",
order.product-lineitems.product-lineitem.tax as "tax",
order.customer.customer-no as "customer-no"
| eval combine=mvzip(mvzip(mvzip(mvzip(coalesce(productid,""),coalesce(quantity,""),"!!#@#!!"),coalesce(baseprice,""),"!!#@#!!"),coalesce(netprice,""),"!!#@#!!"),coalesce(adjustcouponid,""),"!!#@#!!")
 | mvexpand combine
| eval allvalues=split(combine,"!!#@#!!")
| eval "adjust-coupon-id"=mvindex(allvalues,4)
| eval "net-price"=mvindex(allvalues,3)
| eval "base-price"=mvindex(allvalues,2)
| eval "quantity"=mvindex(allvalues,1) 
| eval "product-id"=mvindex(allvalues,0)
| table "order-no", "order-date", "currency", "country-code","quantity", "base-price", "net-price", "product-id", "customer-no", "adjust-coupon-id" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;order-no    order-date  currency    country-code    quantity    base-price  net-price   product-id  customer-no adjust-coupon-id
1   2017-07-31T13:13:31.000Z    AUD AU  1.0 30.00   27.27   2   00436933    BFFYAY
1   2017-07-31T13:13:31.000Z    AUD AU  1.0 50.00   45.45   3   00436933    BFFYAY
1   2017-07-31T13:13:31.000Z    AUD AU  1.0 45.00   40.91   4   00436933    BFFYAY
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Aug 2017 01:59:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362849#M107202</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-16T01:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362850#M107203</link>
      <description>&lt;P&gt;That works for when the entire MV is null, but doesn't work for when there are 4 rows, but in the MV there is 3 of them which has a value, but the 4th one is non-existent.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 02:10:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362850#M107203</guid>
      <dc:creator>shinglau</dc:creator>
      <dc:date>2017-08-16T02:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Flatten Search Results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362851#M107204</link>
      <description>&lt;P&gt;Try this ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=* OR index=_*) (index="myindex" "order{@order-no}"="1" "order.customer.customer-no"="*")
 | rename order{@order-no} as "order-no",
     order.order-date as "order-date",
     order.currency as "currency",
     order.shipments.shipment.shipping-address.country-code as "country-code",
     order.product-lineitems.product-lineitem.product-id as "productid",
     order.product-lineitems.product-lineitem.quantity as "quantity",
     order.product-lineitems.product-lineitem.base-price as "baseprice",
     order.product-lineitems.product-lineitem.net-price as "netprice",
     order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.promotion-id as "adjustpromotionid",
     order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.campaign-id as "adjustcampaignid",
     order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.coupon-id as "adjustcouponid",
     order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.lineitem-text as "adjustlineitemtext",
     order.product-lineitems.product-lineitem.price-adjustments.price-adjustment.base-price as "adjustbaseprice",
     order.product-lineitems.product-lineitem.tax as "tax",
     order.customer.customer-no as "customer-no"
 | streamstats count as recno
 | eval myFan=mvrange(0,mvcount(quantity))
 | mvexpand myFan
 | eval productid=mvindex(productid,myFan)
 | eval quantity=mvindex(quantity,myFan)
 | eval baseprice=mvindex(baseprice,myFan)
 | eval netprice=mvindex(netprice,myFan)

 | rename COMMENT as "To accurately line up this part of the data, you should go back to extract"
 | rename COMMENT as "the data directly from the JSON for each line-item by productid."
 | rename COMMENT as "We would need a properly formatted JSON sample to code that extract from the JSON or the _raw,"
 | rename COMMENT as "So this is just a placeholder method."
 | eval adjustpromotionid=mvindex(adjustpromotionid,myFan)
 | eval adjustcampaignid=mvindex(adjustcampaignid,myFan)
 | eval adjustcouponid=mvindex(adjustcouponid,myFan)
 | eval adjustlineitemtext=mvindex(adjustlineitemtext,myFan)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2017 19:33:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Flatten-Search-Results/m-p/362851#M107204</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-06T19:33:40Z</dc:date>
    </item>
  </channel>
</rss>

