Splunk Enterprise

How to do a stats count by on only some array elements?

thomas_nguyen
Engager

Hey everyone. I am trying to do a stats count by items{}.description, items{}.price but I'd like to filter out some of the items. In this example, I'd like to include "description one" and "description two", but not "description three".  In the real situation there is many more that I'd like to include and to exclude.

Is this possible?

 

 

 

"time": "01:01:01",
"items": [
    {
      "description": "description one",
      "price": "$220"
    },
    {
      "description": "description two",
      "price": "$10"
    },
    {
      "description": "description three",
      "price": "$50"
    }
]

 

 

 

 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try extracting the items from the collection with spath, then mvexpand the multi-value field, then extract the next level down, and filter the values you want to keep

 

| spath items{} output=items
| mvexpand items
| spath input=items
| where description IN ("description one", "description two")
| stats count by description, price

 

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try extracting the items from the collection with spath, then mvexpand the multi-value field, then extract the next level down, and filter the values you want to keep

 

| spath items{} output=items
| mvexpand items
| spath input=items
| where description IN ("description one", "description two")
| stats count by description, price

 

0 Karma

thomas_nguyen
Engager

@ITWhisperer thank you so much. That worked. I did have to tweak it slightly but I was able to get what I was looking for. 

| spath output=items path=items{}
| mvexpand items
| spath input=items
| where description IN ("description one", "description two")
| stats count by description, price
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Thanks - I updated the solution (a typo on my part) 😀

0 Karma
Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...