Splunk Search

Getting results from multiple searches without append or join

Chandras11
Communicator

Hi All,

I have 2 sourcetypes as following:-

Sourcetype_A
 Ticket | Main_Ticket | Value | Line  | LinkedTicket

 Sourcetype_B
 Ticket | Main_Ticket | Value | Line | LinkedTicket

Now I need to find the results from sourcetype_B and if the sourcetype_B.Main_Ticket = Sourcetype_A.Ticket then I need to combine the results as:-

sourcetype_B.Ticket | sourcetype_B.Main_Ticket | sourcetype_B.Value | sourcetype_B.Line  | Sourcetype_A.Ticket | Sourcetype_A.Value 

Currently, I a using the join approach but I am not fetching all the results as my database have 500,000+ entries and join look for the first 50000 entries. The second approach is using "append" but still, it is very slow.

Is it possible to use Stats values(X) as X by Ticket if all the fields in both sourcetype are same but the field to compare (sourcetype_B.Main_Ticket = Sourcetype_A.Ticket) are different?

Thanks a lot in advance.

0 Karma
1 Solution

HiroshiSatoh
Champion

Try this search sentence!

sourcetype=Sourcetype_A OR sourcetype=Sourcetype_B
|fields  Ticket,Main_Ticket,Value,Line,LinkedTicket,sourcetype
|eval match_key=if(sourcetype=Sourcetype_A,Ticket,Main_Ticket)
|stats latest(*) as * ,dc(sourcetype) as match_count by match_key
|where match_count=2

※|where match_count=2
Exclude unmatched logs

View solution in original post

woodcock
Esteemed Legend

Like this:

index=AlwaysSpecifyAnIndex AND (sourcetype=Sourcetype_A OR sourcetype=Sourcetype_B)
| fields sourcetype Ticket Main_Ticket Value Line LinkedTicket
| eval Joiner = if((sourcetype==Sourcetype_A), Ticket, Main_Ticket),
       ATicket = if((sourcetype==Sourcetype_A), Ticket, null()),
       AValue = if((sourcetype==Sourcetype_A), Value, null()),
       Ticket = if((sourcetype==Sourcetype_B), Ticket, null()),
       Main_Ticket = if((sourcetype==Sourcetype_B), Main_Ticket , null()),
       Value = if((sourcetype==Sourcetype_B), Value, null()),
       Line = if((sourcetype==Sourcetype_B), Line, null())
| stats values(*) AS * dc(sourcetype) AS numSourcetypes BY Joiner
| where numSourcetypes==2
| table Joiner Ticket Main_Ticket Value Line ATicket AValue

Chandras11
Communicator

Sorry for the delay in response.
The only issue is that there are 64 columns in Sourcetpye_A and sourcetype_B and out of those 64 at least 14 are really needed. The code will be really big with it.

0 Karma

HiroshiSatoh
Champion

Try this search sentence!

sourcetype=Sourcetype_A OR sourcetype=Sourcetype_B
|fields  Ticket,Main_Ticket,Value,Line,LinkedTicket,sourcetype
|eval match_key=if(sourcetype=Sourcetype_A,Ticket,Main_Ticket)
|stats latest(*) as * ,dc(sourcetype) as match_count by match_key
|where match_count=2

※|where match_count=2
Exclude unmatched logs

Chandras11
Communicator

Thanks I am trying to use it in my query. 🙂

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Defend at Machine Speed: Your Guide to Security Sessions at .conf26

Splunk .conf26   With threats moving at machine speed and attack surfaces expanding across hybrid ...

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...