Splunk Search

Lookup command - multiple input fields

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

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

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

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

Motivator

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

0 Karma

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

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

Communicator

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

Motivator

thank you!

0 Karma

Explorer

Thank you for this one mate, it helps !

0 Karma

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

SplunkTrust
SplunkTrust

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

State of Splunk Careers

Access the Splunk Careers Report to see real data that shows how Splunk mastery increases your value and job satisfaction.

Find out what your skills are worth!