Splunk Search

Field extraction.

sandeepmakkena
Contributor

I have a raw event like this for each order, if a user buys two products of different units how can I tie each product to a specific quantity.

Items: [ [-]
{ [-]
commitCode: 2

deliveryType:

partNumber: P123
product: 3 Wireless Phone

promos: [ [-]
Auto dependency

]

qty: 10
resolvedDate: 04/04/04
shipMethodCode: A8
}

{ [-]
commitCode: 2

deliveryType: th
partNumber: P345

product: Pen

promos: [ [+]
]

qty: 1

resolvedDate: 04//04/04。

shipMethodCode: A8
}

I want to calculate the quantity of each product, but when I extracted qty and do stats count by PartNumber. It is giving incorrect events. Can someone help me how to work a way around that.
Thanks for your time.

0 Karma

poete
Builder

Hello @sandeepmakkena,

here is the way to go :

| makeresults 
| eval _raw="{\"Items\": [ {\"commitCode\": 2, \"deliveryType\":\"\",\"partNumber\": \"P123\",\"product\": \"3 Wireless Phone\",\"promos\": [ \"Auto dependency\"], \"qty\": 10,\"resolvedDate\": \"04/04/04\", \"shipMethodCode\": \"A8\"},
{ \"commitCode\": 2, \"deliveryType\": \"th\", \"partNumber\": \"P345\",\"product\": \"Pen\",\"promos\": [],\"qty\": 1,\"resolvedDate\": \"04/04/04\",\"shipMethodCode\": \"A8\"}]}"
| spath
| rename Items{}.qty as qty Items{}.product as product
| table qty product
| eval tmp=mvzip(product,qty)
| mvexpand tmp
| eval tmp = split(tmp,",") 
| eval product=mvindex(tmp,0)
| eval qty=mvindex(tmp,1)
| stats sum(qty) as nb by product
0 Karma
Get Updates on the Splunk Community!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...