Splunk Search

Search strings in a different fields with different name under different indexes

splunkerer
Path Finder

I have two indexes including command line arguments, one has field name arg, the other one has field name command, what is the best practice to search some strings on both fields under different indexes to create alert if matches. 

index=A arg="*command_string_to_search*"
OR 
index=B command="*command_string_to_search*"

How can we improve this search from performance standpoint? 

Thanks,

0 Karma
1 Solution

venkatasri
SplunkTrust
SplunkTrust

Hi @splunkerer 

What you have written is fine as you have data in two different indexes. Fieldnames doesn't matter though they have common values as long as you have OR condition.

Couple of points to fine tune:

  • Try not to use leading wildcards, if you know upfront  just give full value there instead to start with * and end with *
  • use fields command  <your_search> | fields <field1> <field2> , this limits the processing of unnecessary fields hence impact on SH is minimal
  • if your fields arg, command are indexed fields try to see if you can use | tstats
  • If your SH pointed to various indexers ( pre-prod, prod etc) aka splunk_server field, if you upfront aware your indexer names then use splunk_server field

----

An upvote would be appreciated if this reply helps and Accept the solution!

View solution in original post

venkatasri
SplunkTrust
SplunkTrust

Hi @splunkerer 

What you have written is fine as you have data in two different indexes. Fieldnames doesn't matter though they have common values as long as you have OR condition.

Couple of points to fine tune:

  • Try not to use leading wildcards, if you know upfront  just give full value there instead to start with * and end with *
  • use fields command  <your_search> | fields <field1> <field2> , this limits the processing of unnecessary fields hence impact on SH is minimal
  • if your fields arg, command are indexed fields try to see if you can use | tstats
  • If your SH pointed to various indexers ( pre-prod, prod etc) aka splunk_server field, if you upfront aware your indexer names then use splunk_server field

----

An upvote would be appreciated if this reply helps and Accept the solution!

splunkerer
Path Finder

Thanks @venkatasri for all great recommendations. 

I was thinking it may be useful to use rex in a field instead of using a couple of heavy string? what do you think on that?

| rex field=command "(string_1)|(string_2)|(string_3)|(strings_4)"

but the problem here is strings which will be searched can be anywhere of the field

0 Karma

venkatasri
SplunkTrust
SplunkTrust

@splunkerer  | rex is for field extractions not for search. What you have written originally that is self sufficient though the command/arg values are long it does job well when you follow field = "value" rather than doing raw search. 

if you think the fields match many sourcetypes/source under index=A OR B then specify the sourcetype= , source= , host= (this is fundamental searching a whole index takes time) the more details you put in upfront to SPL then results would be narrowed down and faster.

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...