Splunk Search

Error when using a Datamodel in a Macro

ebs
Communicator

Hi,

I'm using the following datamodel search:

| datamodel Test_Ping_Access summariesonly=true search | search "Ping_Access__TEST.date"=$date$ | stats count(exchangeId)

And I've confirmed its working, but when I use it in a macro I get this error:

Error in 'SearchParser': The datamodel command can only be used as the first command on a search

How can I resolve this?

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

When creating a macro that uses a generating command, such as datamodel or inputlookup, you need to leave the | symbol out of the macro definition, so your macro will just be

datamodel Test_Ping_Access summariesonly=true search | search "Ping_Access__TEST.date"=$date$ | stats count(exchangeId)

and then you use it like this

| `my_datamodel_macro(date)`

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

When creating a macro that uses a generating command, such as datamodel or inputlookup, you need to leave the | symbol out of the macro definition, so your macro will just be

datamodel Test_Ping_Access summariesonly=true search | search "Ping_Access__TEST.date"=$date$ | stats count(exchangeId)

and then you use it like this

| `my_datamodel_macro(date)`

ebs
Communicator

Thanks!

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...