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!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...