Splunk Search

Limited search join

mattiasrs
Explorer

Hello awesome community!

I got help from here once before so I will try again.

I have two indexes, Index A and Index B.

Fields:

Index A: id

Index B: pid, address

I want to retrieve the top 10 count ids from Index A and then join these 10 with Index B to retrieve the address info.

This is my search (simplified) to retrieve the top 10 ids from Index A:

index = A

| stats count by id

| sort -count

| head 10

Index B is huge so I only want to search it for the top 10 ids found from Index A search above.

How can I use the results found from the above search into a search from Index B?

Many thanks

Labels (2)
Tags (2)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mattiasrs,

you cannot use commands that use subsearches (like join) because there's the limit of 50,000 results in subsearches and then because join is a very slow command.

So I hint to try something like this:

index=A OR index=B
| eval id=coalesce(id, pid)
| stats count(eval(index="A")) AS count values(address) AS address by id
| sort -count
| head 10

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mattiasrs,

the B index is huge, so you cannot use a subsearch, the only way is to put both the indexes in the main search and count the events where index=A for each id, taking also the value of the IP address from the index=B.

Ciao.

Giuseppe

0 Karma

mattiasrs
Explorer

Hi Giuseppe and thanks for your reply!

I tried your solution but it seems like it is searching through everything from Index B, which is not an option here due to the amount of data in that index. Also, maybe worth mentioning is that the pid field in index B contains data that is not present in Index A so I need it to only consider the top 10 count from Index A.

Any idea what I'm doing wrong?

0 Karma
Get Updates on the Splunk Community!

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...