Splunk Search

How to remove elements from first search with a second search?

Andresfrj
Engager

Andresfrj_0-1659450865708.png

 

Hello,

I want to perform the above operation. I have a first search (A), and want to remove elements in it (in this case a field called id) from a second search B. What is the most clean way of implementing this such search? 

 

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Andresfrj,

you have to use a subsearch.

Only limit is that a subsearch can have max 50,000 results,

so you can use something lieke this.

The rule is to identify key fields.

So if the key field is field1, you can run something like this:

index=indexA NOT [ search index=indexB | fields field1 ]
| ...

if instead subsearch can have more than 50,000 results, the solution is just a little more complex:

index=indexA OR index=indexB
| stats earliest(_time) AS _time dc(index) AS index_count values(index) AS index BY field1
| where  index_count=1 AND index=indexA

you can add to the stats command all the "values(field) AS field" you need.

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Andresfrj,

you have to use a subsearch.

Only limit is that a subsearch can have max 50,000 results,

so you can use something lieke this.

The rule is to identify key fields.

So if the key field is field1, you can run something like this:

index=indexA NOT [ search index=indexB | fields field1 ]
| ...

if instead subsearch can have more than 50,000 results, the solution is just a little more complex:

index=indexA OR index=indexB
| stats earliest(_time) AS _time dc(index) AS index_count values(index) AS index BY field1
| where  index_count=1 AND index=indexA

you can add to the stats command all the "values(field) AS field" you need.

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Andresfrj,

good for you, see next time!

Ciao and happy splunking

Giuseppe

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

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

here is excellent description how to avoid to use command join when you are doing “sql joins” https://community.splunk.com/t5/Splunk-Search/What-is-the-relation-between-the-Splunk-inner-left-joi...

r. Ismo

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...