Splunk Search

How to combine the result of 2 search queries?

ID_SplunkUser
Path Finder

Hi All,

I have a scenario to combine the search results from 2 queries. For Type= 101 I don't have fields "Amount" and "Currency", so I'm extracting them through Regex in separate query. I can't combine the regex with the main query due to data structure which I have. At the end I just want to display the Amount and Currency with all the fields.

1st query: 
sourcetype=abc | table Currency, Amount, Address, Type

2nd Query:
sourcetype=abc | rex field=_raw max_match=0 "(:32B:(?<Curr>.{3})(?<Amnt>.[^\n]+))" |where Type=101|eval fields = mvzip(Curr,Amnt,"#") | mvexpand fields | rex field=fields "(?<Currency>\w+)#(?<Amount>\S+)"

Other than 101 Type all other messages are having Amount and Currency fields. I just want to combine both results.

Thanks.

Tags (1)
0 Karma
1 Solution

inventsekar
SplunkTrust
SplunkTrust

please try -

 sourcetype=abc | table Currency, Amount, Address, Type | append [ sourcetype=abc | rex field=_raw max_match=0 "(:32B:(?<Curr>.{3})(?<Amnt>.[^\n]+))" |where Type=101|eval fields = mvzip(Curr,Amnt,"#") | mvexpand fields | rex field=fields "(?<Currency>\w+)#(?<Amount>\S+)"]
thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !

View solution in original post

0 Karma

woodcock
Esteemed Legend

Try this:

 sourcetype=abc | rex field=_raw max_match=0 "(:32B:(?<Curr>.{3})(?<Amnt>.[^\n]+))" |where Type=101|eval fields = mvzip(Curr,Amnt,"#") | mvexpand fields | rex field=fields "(?<Currency>\w+)#(?<Amount>\S+)" | stats sum(Amount) As Amount BY Currency Address Type
0 Karma

vivek_manoj
Explorer

you can use appendcols command for combining two search query.
like
index="abc"| search user="hostee"| appendcols[index="xyz"|search host="apple"]

0 Karma

sundareshr
Legend

I don't think you need a sub-search. Try this (assuming your regex is extracting values correctly).

sourcetype=abc | rex field=_raw max_match=0 "(:32B:(?<Curr>\w{3})(?<Amnt>[^\n]+))" | eval fields = mvzip(Curr, Amnt, "#") | mvexpand fields | rex field=fields "(?<Currency>\w+)#(?<Amount>\S+) | table Currency, Amount, Address, Type

OR

sourcetype=abc | rex field=_raw max_match=0 "(:32B:(?<Curr>\w{3})(?<Amnt>[^\n]+))" | eval fields = mvzip(Curr, Amnt, "#") | mvexpand fields | rex field=fields "(?<Currency>\w+)#(?<Amount>\S+) | stats count by Currency, Amount, Address, Type
0 Karma

inventsekar
SplunkTrust
SplunkTrust

please try -

 sourcetype=abc | table Currency, Amount, Address, Type | append [ sourcetype=abc | rex field=_raw max_match=0 "(:32B:(?<Curr>.{3})(?<Amnt>.[^\n]+))" |where Type=101|eval fields = mvzip(Curr,Amnt,"#") | mvexpand fields | rex field=fields "(?<Currency>\w+)#(?<Amount>\S+)"]
thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

ID_SplunkUser
Path Finder

Thanks for the reply.

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

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

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...