Splunk Search

Lookup command - multiple input fields

HeinzWaescher
Motivator

Hi,

is it possible to use more than one input field within a lookup command?
The lookuptable looks like this:

User | Country | FieldA

I tried it like this, but it didn't work:

| lookup lookup.csv User, Country OUTPUT fieldA

BR

Heinz

Tags (2)
1 Solution

MuS
SplunkTrust
SplunkTrust

Hi HeinzWaescher,

see the docs about lookup

Note: The lookup command can accept multiple lookup and local fields and destfields. For example:

lookup <lookup-table-name> <lookup-field1> AS <local-field1>, <lookup-field2> AS <local-field2> OUTPUTNEW <lookup-destfield1> AS <local-destfield1>, <lookup-destfield2> AS <local-destfield2>

the only thing you must be aware of, is that the local-field should exists if you use it in a lookup. That would be in your use case User and Country.

hope this helps ...

cheers, MuS

View solution in original post

srujan9292
Explorer

Hi MuS,

What should be the query if we need to perform the search on same local-field?

lookup lookup-table-name lookup-field1 AS local-field1, lookup-field2 AS local-field1
OUTPUT lookup-field1, lookup-field2, lookup-field3

Here lookup-field3 is corresponding field in lookup table.
I have tried the above format, but it says no results found!!

Thanks in advance.

0 Karma

MuS
SplunkTrust
SplunkTrust

Hi HeinzWaescher,

see the docs about lookup

Note: The lookup command can accept multiple lookup and local fields and destfields. For example:

lookup <lookup-table-name> <lookup-field1> AS <local-field1>, <lookup-field2> AS <local-field2> OUTPUTNEW <lookup-destfield1> AS <local-destfield1>, <lookup-destfield2> AS <local-destfield2>

the only thing you must be aware of, is that the local-field should exists if you use it in a lookup. That would be in your use case User and Country.

hope this helps ...

cheers, MuS

HeinzWaescher
Motivator

After some adjustments in my search, it works like expected. Thanks a lot 🙂

0 Karma

MuS
SplunkTrust
SplunkTrust

let's take this example,

col1,col2,col3,col4
100,300,500,yes
200,400,600,no

Configure this a lookup named mylookup and you can use the lookup in a search like this:

basesearch | lookup mylookup col1 as field1, col2 as field2, col3 as field3 OUTPUT col4

For each event where all the input values matches, there will be a resulting field, col4, available for that event.
So if you have field1=100 AND field2=300 AND field3=500 then you will get back col4=yes

gesman
Communicator

I wonder if it's possible to do "OR" logic, instead of "AND" logic?
Say, if I have field1=100 OR field2=300 OR field3=500 then I will get back col4=yes

guarisma
Contributor

To make an OR you just make multiple lookup with OUTPUTNEW instead of OUTPUT

my search
| lookup mylookup col1 AS field1 OUTPUTNEW col4
| lookup mylookup col2 AS field1 OUTPUTNEW col4
| lookup mylookup col3 AS field1 OUTPUTNEW col4

nick405060
Motivator

thank you!

0 Karma

pleymort
Explorer

Thank you for this one mate, it helps !

0 Karma

HeinzWaescher
Motivator

Hi MuS,

I'm not using inputlookup, the table is just called lookup.csv.

The inputfields are existing in the lookuptable and the event. It is an "and" combination of the inputfields, correct? So the lookup should work and add fieldA for an event, when this combination "User/Country" exists in the lookuptable as well.

0 Karma

MuS
SplunkTrust
SplunkTrust

or are you using inputlookup because you are providing a lookup.csv in your example?

Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...