Splunk Search

paranthesis error in search query

secure
Explorer

Hi,

Im trying to use an OR function in the below query trying to combine two indexes and then use stats function like an alternate for join command

(index=serverdata sourcetype="server:stats" | rex "app_code=\"(?<application_code>[|w.\"]*)" ) OR (index="hostapp" source=hostDB_Table dataasset="*host_Data*")

secure_0-1738790565197.png

i have tried to use escape characters but its still not working

thanks 

 

 

Labels (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @secure ,

as @PickleRick said, in the main search you cannot use a command as rex.

You have two choices:

move the rex after the main search:

(index=serverdata sourcetype="server:stats") OR (index="hostapp" source=hostDB_Table dataasset="*host_Data*")
| rex "app_code=\"(?<application_code>[|w.\"]*)"

or use append:

(index=serverdata sourcetype="server:stats" 
| rex "app_code=\"(?<application_code>[|w.\"]*)"
| append [ search index="hostapp" source=hostDB_Table dataasset="*host_Data*")]

This second solution runs only if you have, in the secondary search, less than 50,000 results, for this reason I orefer the first one.

In addition, there's a third solution that I prefer: if you create a fixed field extraction, using the regex, you don't need to insert it in the search and you can use only the main search:

(index=serverdata sourcetype="server:stats") OR (index="hostapp" source=hostDB_Table dataasset="*host_Data*")

Ciao.

Giuseppe

0 Karma

PickleRick
SplunkTrust
SplunkTrust

The 50k results limit for subsearch applies only to join! The default limit for a subsearch is 10k results.

PickleRick
SplunkTrust
SplunkTrust

It doesn't work like that. Parentheses group search conditions only. You can't spawn separate post-processing command for part of your data this way. You would need to use multisearch or append. But in your case it's probably not needed. Just do your rex command after the initial search.

Unrelated note - don't use wildcards at the beginning of your search term unless you really can't avoid it.

0 Karma

NevilleRadcliff
Loves-to-Learn

Thanks, I will keep it in mind.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @NevilleRadcliff ,

let us know if we can help you more, or, please, accept one answer for the other people of Community.

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL  The Splunk AI Assistant for SPL ...

Buttercup Games: Further Dashboarding Techniques (Part 5)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Customers Increasingly Choose Splunk for Observability

For the second year in a row, Splunk was recognized as a Leader in the 2024 Gartner® Magic Quadrant™ for ...