Hi All,
I have a search with a subsearch that references a lookup file test.csv with a single field. "Account_Name". I want to remove names from the lookup table that meet a certain criteria.
The search below currently gives the results that I want removed from the lookup file test.csv, but I cannot seem to figure out how to get the inverse of these results from the lookup file. I want everything in the lookup that does not match the result of the below query. Any advice? For example, if the below search outputs Bob and the lookup contains Bob, Alice, and Dave, I would want my final results to be Alice and Dave to overwrite back into test.csv. That's my line of thinking at least, I could be approaching this in a bad way.
index=exampleindex EventCode=4722 | stats by Target_Account_Name | rename Target_Account_Name as Account_Name | search [inputlookup test.csv | table Account_Name] | table Account_Name
So, you want to exclude account names which are present in data, so do it like this
index=exampleindex EventCode=4722
| stats by Target_Account_Name
| rename Target_Account_Name as Account_Name
| eval origin=1
| append
[ inputlookup test.csv
| table Account_Name
| eval origin=0]
| stats max(origin) as origin by Account_Name
| where origin=0
i.e. for all events, set the origin=1. Then append the entire lookup with origin=0 and do a max of origin by name. Those where the max origin is 0 are ONLY from lookup, so the where clause will pick them
So, you want to exclude account names which are present in data, so do it like this
index=exampleindex EventCode=4722
| stats by Target_Account_Name
| rename Target_Account_Name as Account_Name
| eval origin=1
| append
[ inputlookup test.csv
| table Account_Name
| eval origin=0]
| stats max(origin) as origin by Account_Name
| where origin=0
i.e. for all events, set the origin=1. Then append the entire lookup with origin=0 and do a max of origin by name. Those where the max origin is 0 are ONLY from lookup, so the where clause will pick them
Thanks for the suggestion!
I was also able to do what I wanted with the below search, but yours seems a bit more efficient.
| inputlookup test.csv | search NOT [search index=exampleindex EventCode=4722 | stats by Target_Account_Name | rename Target_Account_Name as Account_Name | table Account_Name ]