Splunk Search

How to use append to work like Inner join

Punnu
Path Finder

I have two searches  and I only want to find rows which has common MessageID . Currently it is returning extra row because of second search . 

Query before Or is returning 100 records  and after OR one was returning 110 rows  and for those extra 10 rows messageID in first is NULL , So I want to drop those messages . Please help how can i  change this query to make it work . I am trying to find count of matched IDs and  list of all such ids 

```query for apigateway call```
(index=aws_np earliest="03/28/2025:13:30:00" latest="03/28/2025:14:35:00" Method response body after transformations: sourcetype="aws:apigateway" business_unit=XX aws_account_alias
="XXXX" network_environment=xxXXX source="API-Gateway-Execution-Logs*" (application="xXXXXX" OR application="xXXXX-xXX") 
| rex field=_raw "Method response body after transformations: (?<json>[^$]+)" 
| spath input=json path="header.messageID" output=messageID 
| spath input=json path="payload.statusType.code" output=status 
| spath input=json path="payload.statusType.text" output=text 
|  spath input=json path="header.action" output=action 
| where status=200  and action="Create" `
| rename _time as request_time 
| table messageID, request_time) 
| append 
```query for 2nd query call```
    [ search kubernetes_cluster="eks-XXX*" index="aws_XXX" sourcetype = "kubernetes_logs" source = *XXXX*  "sendData" 
    | rex field=_raw "sendData: (?<json>[^$]+)" 
    | spath input=json path="header.messageID" output=messageID 
    | rename _time as pubsub_time 
    | table messageID, pubsub_time
 ] |  stats values(request_time) as request_time  values(pubsub_time) as pubsub_time  by messageID 

 

 

 

Labels (2)
Tags (1)
0 Karma
1 Solution

livehybrid
Super Champion

Hi @Punnu 

If you wanted a count of the unique messageID after filtering then a simple stats count should do, as we've already stats by messageID

| stats count 

 

🌟 Did this answer help you? If so, please consider:

  • Adding kudos to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing.

View solution in original post

isoutamo
SplunkTrust
SplunkTrust
0 Karma

livehybrid
Super Champion

Hi @Punnu 

To achieve an inner join effect and only keep results where messageID exists in both searches, you can filter the results after your stats command to remove rows where request_time is null (meaning the messageID only existed in the second search).

 Add | where isnotnull(request_time) after your stats command.

 

🌟 Did this answer help you? If so, please consider:

  • Adding kudos to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

Punnu
Path Finder

hi @livehybrid  Thank you for reply . I would like to ask one more question . Post filtering  out records how we can find count of messageID 

0 Karma

livehybrid
Super Champion

Hi @Punnu 

If you wanted a count of the unique messageID after filtering then a simple stats count should do, as we've already stats by messageID

| stats count 

 

🌟 Did this answer help you? If so, please consider:

  • Adding kudos to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing.

yuanliu
SplunkTrust
SplunkTrust

If all you want is to remove those extra messageID's, you can simply remove those with null request_time, like

| search request_time = *
Get Updates on the Splunk Community!

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...

Splunk App Dev Community Updates – What’s New and What’s Next

Welcome to your go-to roundup of everything happening in the Splunk App Dev Community! Whether you're building ...

The Latest Cisco Integrations With Splunk Platform!

Join us for an exciting tech talk where we’ll explore the latest integrations in Cisco &#43; Splunk! We’ve ...