Splunk Search

Is there any way to get the fields and its expression from datamodel

sivaranjiniG
Path Finder

Hello,

Is there any way to get fieldname and its expression from datamodel using rest api(using splunk query)?

I am already using this query but here fields and its expressions are shuffled.

 

| datamodel 
| spath output=modelName modelName
|search modelName=Network_Traffic
|rex max_match=0 field=_raw "\[\{\"fieldName\":\"(?<fields>[^\"]+)\""
|rex max_match=0 field=_raw "\"expression\":\"(?<expression>.*?)\"}"
|table fields expression

 

 

 

 

Labels (1)
0 Karma
1 Solution

livehybrid
SplunkTrust
SplunkTrust

Does the following search help? This uses json_ functions and mvexpand to split out and then match up the fields and expressions:

| datamodel 
| spath output=modelName modelName
|search modelName=Network_Traffic
| eval objects=json_array_to_mv(json_extract(_raw,"objects"))
| mvexpand objects
| eval calculations=json_array_to_mv(json_extract(objects,"calculations"))
| mvexpand calculations
| eval outputFields=json_array_to_mv(json_extract(calculations,"outputFields"))
| mvexpand outputFields
| eval fieldName=json_extract(outputFields,"fieldName")
| eval expression=json_extract(calculations,"expression")
| table modelName fieldName expression



livehybrid_0-1738499308118.png

 

View solution in original post

livehybrid
SplunkTrust
SplunkTrust

Does the following search help? This uses json_ functions and mvexpand to split out and then match up the fields and expressions:

| datamodel 
| spath output=modelName modelName
|search modelName=Network_Traffic
| eval objects=json_array_to_mv(json_extract(_raw,"objects"))
| mvexpand objects
| eval calculations=json_array_to_mv(json_extract(objects,"calculations"))
| mvexpand calculations
| eval outputFields=json_array_to_mv(json_extract(calculations,"outputFields"))
| mvexpand outputFields
| eval fieldName=json_extract(outputFields,"fieldName")
| eval expression=json_extract(calculations,"expression")
| table modelName fieldName expression



livehybrid_0-1738499308118.png

 

Get Updates on the Splunk Community!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

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

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