Splunk Search

How to combine two search results in a better way

dibyaranjan3177
New Member

Hello,

I am trying to create a query which will help me combine results from two search results by doing this:

 index=some_index source="log_source" AND "Not Updated - sourceId" 
 | stats count as RejectedEvents 
 | appendcols [
     search index=some_index source="log_source" 
     | rex ".*Batch info: completed, processed entities: (?<numberOfMessage>.*)"
     | stats sum(numberOfMessage) as ProcessedEvents
   ] 
 | eval total = ProcessedEvents + RejectedEvents
 | fields total

This query works fine, but is insanely slow. Any help on making this better?

0 Karma

woodcock
Esteemed Legend

Try this:

index="some_index" AND source="log_source"
| rex ".*Batch info: completed, processed entities: (?<numberOfMessage>.*)"
| stats sum(numberOfMessage) AS ProcessedEvents count AS total_raw count(eval(searchmatch("Not Updated - sourceId"))) AS RejectedEvents
| eval total_true = ProcessedEvents + RejectedEvents
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This may be a little better.

(index=some_index source="log_source") OR (index=some_index source="log_source" "Not Updated - sourceId" )
| eval Rejected = if (match(_raw, "Not Updated - sourceId"), 1, 0)
| rex ".*Batch info: completed, processed entities: (?<numberOfMessage>.*)"
| stats sum(Rejected) as RejectedEvents, sum(numberOfMessage) as ProcessedEvents
| eval total = ProcessedEvents + RejectedEvents
| fields total
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...