Splunk Search

event values have same name

scumbum
New Member

My event data contains the following:

target[ 
     { 
       alternateIdapplication1
       detailEntry: { 
       }

       displayNameOpenID Connect Client
       idasdfasdf
       typeAppInstance
     }
     { 
       alternateIdunknown
       detailEntrynull
       displayNameUnregistered Device - Default
       id: adsfasdf
       typeRule

I want to do a | stats count by target.displayname but only on events that have target.type=Rule. It is possible to have more than two entries as well so cant just say always select second entry.

Labels (4)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

A pointer: When anonymizing structured data, make sure the structure itself is compliant.  I think you mean your event looks like

{"target": [
     { 
       "alternateId": "application1",
       "detailEntry": {
       },
       "displayName": "OpenID Connect Client",
       "id": "asdfasdf",
       "type": "AppInstance"
     },
     { 
       "alternateId": "unknown",
       "detailEntry": "null",
       "displayName": "Unregistered Device - Default",
       "id": "adsfasdf",
       "type": "Rule"
     }
  ]
}

You can use mvexpand before filter or use mvfilter.  Using mvexpand is more traditional:

| spath path=target{}
| mvexpand target{}
| where json_extract('target{}', "type") == "Rule"
| eval displayName = json_extract(target, "displayName")

Use of JSON functions above assumes that you use Splunk 8 or later, but the mvexpand method can still work without JSON functions; you just use another round of spath.

Using mvfilter, on the other hand, requires JSON functions first introduced in Splunk 8.

| spath path=target{}
| eval target = mvfilter(json_extract('target{}', "type") == "Rule")
| eval displayName = json_extract(target, "displayName")

Hope this helps. 

Tags (3)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...