Splunk Search

How to change from join command (executed twice) to stats command?

tehong
Explorer

Hi Experts!

I am trying to REPLACE the join command to the stats command because the subsearch result exceeds 50000.

However, I don't know how to replace the join command to the stats command because this spl uses join twice.

Can you please advise? Thanks in advance!!

index=myindex sourcetype=A  LogicalName="new_endpoiint"
| join left=L right=R where L.new_contract.Name = R.new_contract_code
[ search index=myindex sourcetype=A LogicalName="new_contract" ]
| join left=L2 right=R2 where L2.R.new_circuit.Name = R2.new_circuit_code
[ search index=cmdb sourcetype=A LogicalName="new_circuit" ]
Labels (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

Use something along the lines of this

(index=myindex sourcetype=A (LogicalName="new_endpoiint" OR LogicalName="new_contract") OR (index=cmdb sourcetype=A LogicalName="new_circuit")
| eval ContractCode=coalesce(new_contractName, new_contract_code)
| eval CircuitCode=coalesce(new_circuitName, new_circuit_code)
| stats values(*) as * by ContractCode CircuitCode

where you are searching initially for data_set_1, data_set_2 and data_set_3. which are your 3 searches. Then you would 'join' the common variables with the coalesce command and the stats command would normally have a split by clause of the join fields, in this case ContractCode and CircuitCode as above.

Hopefully this puts you on the right path

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Use something along the lines of this

(index=myindex sourcetype=A (LogicalName="new_endpoiint" OR LogicalName="new_contract") OR (index=cmdb sourcetype=A LogicalName="new_circuit")
| eval ContractCode=coalesce(new_contractName, new_contract_code)
| eval CircuitCode=coalesce(new_circuitName, new_circuit_code)
| stats values(*) as * by ContractCode CircuitCode

where you are searching initially for data_set_1, data_set_2 and data_set_3. which are your 3 searches. Then you would 'join' the common variables with the coalesce command and the stats command would normally have a split by clause of the join fields, in this case ContractCode and CircuitCode as above.

Hopefully this puts you on the right path

 

PickleRick
SplunkTrust
SplunkTrust

I would be a little bit more explicit. If there are no overlappong fields in the events, your code is perfectly fine but we don't know if it is so. So I'd explicitly choose the files for matching

| eval joiner1=case(LogicalName="new_endpoint",new_contract_name,LogicalName="new_co tract",new_contract_code,1==1,null())
| eval joiner2= <same logic but for the other field>
| stats values(*) as * by joiner1 joiner

 

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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...