Splunk Search

Expand two fields in the json array into table from multiple events

Splunk_321
Path Finder

I am trying to expand couple of fields (locationId, matchRank) using mvexpand. But it only works for shorter duration upto 7days. I want to do this for upto 30 days. My matched_locations json array can have atmost 10 items in it with the presence of both locationId and an associated matchRank in it. We can identify the number of items in matched_locations  by msg.logMessage.numReturnedMatches field. I have thousands of such events.

Below is the query which is working for shorter duration of time, but timing out for longer duration.

#############################################################

index=app_pcf AND cf_app_name="credit-analytics-api" AND message_type=OUT AND msg.logger=c.m.c.d.MatchesApiDelegateImpl
| search "msg.logMessage.numReturnedMatches">0
| eval all_fields = mvzip('msg.logMessage.matched_locations{}.locationId','msg.logMessage.matched_locations{}.matchRank')
| mvexpand all_fields
| makemv delim="," all_fields
| eval LocationId=mvindex(all_fields, 0)
| eval rank=mvindex(all_fields,1)
| fields LocationId, rank
| table LocationId, rank

#############################################################

Below is the sample splunk data for one such event.

###########################################################

cf_app_name: myApp
cf_org_name: myOrg
cf_space_name: mySpace
job: diego_cell
message_type: OUT
msg: {
application: myApp
correlationid: 0.af277368.1669261134.5eb2322
httpmethod: GET
level: INFO
logMessage: {
apiName: Matches
apiStatus: Success
clientId: oh_HSuoA6jKe0b75gjOIL32gtt1NsygFiutBdALv5b45fe4b
error: NA
matched_locations: [
{
city: PHOENIX
countryCode: USA
locationId: bef26c03-dc5d-4f16-a3ff-957beea80482
matchRank: 1
merchantName: BIG D FLOORCOVERING SUPPLIES
postalCode: 85009-1716
state: AZ
streetAddress: 2802 W VIRGINIA AVE
}
{
city: PHOENIX
countryCode: USA
locationId: ec9b385d-6283-46f4-8c9e-dbbe41e48fcc
matchRank: 2
merchantName: BIG D FLOOR COVERING 4
postalCode: 85009
state: AZ
streetAddress: 4110 W WASHINGTON ST STE 100
}
{ [+]
}
{ [+]
}
{ [+]
}
{ [+]
}
{ [+]
}
{ [+]
}
{ [+]
}
{ [+]
}
]
numReturnedMatches: 10
}
logger: c.m.c.d.MatchesApiDelegateImpl

}
origin: rep
source_instance: 1
source_type: APP/PROC/WEB
timestamp: 1669261139716063000
}

###########################################################

Labels (2)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Before you mvexpand, ONLY retain the fields you are interested in. 

At the time you mvexpand 'all_fields' you still have every other field that is in the data, as well as _raw.

As you only care about msg.logMessage.matched_locations{}.locationId and msg.logMessage.matched_locations{}.matchRank, which you zip together, then do

| fields all_fields

 before you mvexpand.

That will help the memory issues. It still may not solve the problem, but will help.

 

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...