Splunk Search

How to use the results from one inputlookup as a variable in a search of a second inputlookup?

andyp54
New Member

Hello

New to Splunk, so I know there is a simple answer to this, but I just can't find it 🙂

I have two inputlookup files.

input-file-A can be searched by username to return a unique id associated with that username.

I want to use this result to search input-file-B to return any fields associated with the unique id.

| inputlookup input-file-B | search unique_id=$unique_id$ [| inputlookup input-file-A | search user_name ="joe_bloggs" | fields unique_id]

...the subseatch runs and works but it's like the unique-id variable doesn't get passed; if I cut and paste a unique-id into the start of the search it also works (so I know the files are there and can be queried etc.

Any advice greatly appreciated!

0 Karma
1 Solution

alacercogitatus
SplunkTrust
SplunkTrust

Ah, it appears you are using subsearch in a manner to which it is not inclined. When using a subsearch, you do not have to worry about tokenization. Whatever is found in the subsearch is returned in SPL, which gets appended by the primary search.

|inputlookup input-file-B | search [ inputlookup input-file-A | search user_name="joe_bloggs" | fields unique_id ]

So here, your subsearch will return:

( unique_id="joes_uniq_id" )

Which will be appended to a search command, so the "expanded" search would look like this:

| inputlookup input-file-B | search ( unique_id="joes_uniq_id" )

View solution in original post

alacercogitatus
SplunkTrust
SplunkTrust

Ah, it appears you are using subsearch in a manner to which it is not inclined. When using a subsearch, you do not have to worry about tokenization. Whatever is found in the subsearch is returned in SPL, which gets appended by the primary search.

|inputlookup input-file-B | search [ inputlookup input-file-A | search user_name="joe_bloggs" | fields unique_id ]

So here, your subsearch will return:

( unique_id="joes_uniq_id" )

Which will be appended to a search command, so the "expanded" search would look like this:

| inputlookup input-file-B | search ( unique_id="joes_uniq_id" )

andyp54
New Member

@alacercogitatus

Thank you so much, worked perfectly 🙂

0 Karma
Get Updates on the Splunk Community!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...