Splunk Search

Search using automatic lookup field

satoto4
New Member

Hello,
I am trying to search source=test.csv (including fieldA) with the attached lookup file.
I define the automatic lookup like 'URL as fieldA OUTPUTNEW DomainGroup AS Domain4fieldA'.
Then I search like 'source=test.csv (Domain4fieldA="G1" OR Domain4fieldA="G2") | eval Service=Domain4fieldA | fields fieldA,Service'

I expect the search result.
Service="G1,G2" in case of fieldA="www.google.co.jp" and
Service="G2" in case of fieldA="www.splunk.com"

But I get ..
Service="G1,G2,G3" in case of fieldA="www.google.co.jp" and
Service="G2,G4" in case of fieldA="www.splunk.com"

How can I search to get the correct result ?
Please notify.

"DomainGroup","URL"
"G1","www.google.co.jp"
"G1","www.google.com"
"G1","www.yahoo.co.jp"
"G2","www.google.co.jp"
"G2","www.amazon.co.jp"
"G2","www.rakuten.co.jp"
"G2","www.splunk.com"
"G3","www.microsoft.com"
"G3","www.google.co.jp"
"G4","www.splunk.com"
"G4","www.apple.com"

Tags (1)
0 Karma

lguinn2
Legend

I understand your thinking, but here is what really happens

First, Splunk identifies all the events in the index that match your criteria. These events have various fieldA values. Let's pretend that the first two events look like this:

 fieldA=www.google.co.jp fieldB=other_data a message here
 fieldA=www.splunk.com fieldB=something_else  a different message here

Second, Splunk performs the lookup (it can't complete the search until it gets the values for Domain4fieldA). When Splunk does the lookup, it finds ALL of the matching values and adds them to the events as a multi-valued field. This effectively does this:

 fieldA=www.google.co.jp fieldB=other_data a message here Domain4fieldA=G1,G2,G3
 fieldA=www.splunk.com fieldB=something_else  a different message here Domain4fieldA=G2,G4

Third, Splunk determines which events now match your criteria - they have a value of either G1 or G2 in the Domain4fieldA. Both events qualify. Note that this does NOT eliminate the non-matching values of Domain4fieldA. It only eliminates events that don't have a matching value for Domain4fieldA.

Finally, the eval and table commands are processed as usual.

If you don't want to see the other values in the multi-valued field, you will need to remove them. Try this command:

source=test.csv (Domain4fieldA="G1" OR Domain4fieldA="G2") 
| eval Service==mvfilter(match(Domain4fieldA, "G1") OR match(Domain4fieldA, "G2")) 
| fields fieldA,Service

satoto4
New Member

Thank you. I could get my expecting data.

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...