Splunk Search

How to combine my two searches pulling data from two different indexes into one search?

dhavamanis
Builder

Need help.

We have two indexes and one index data stats as another index query input,

Over all cost calculation (first search) :

index=aws-bill Subscription="shared-identity" | stats sum(UnBlendedCost) as idxcost 

output:

idxcost 
60

Brand usage from another index (Second search):

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log"   BRAND_NAME="*" | stats count as apicount by BRAND_NAME |sort + BRAND_NAME 

Output:

BRAND_NAME  apicount 
aaaaaaaaa      20
bbbbbb          5
ccccccccc       5

We want to split the idxcost to BRAND_NAME based on apicount,

Final results:

BRAND_NAME  apicount   brand_Cost
aaaaaaaaa      20          40
bbbbbb          5          10
ccccccccc       5          10

Can you please help us with how to write a single search to achieve the final result?

Tags (3)
0 Karma
1 Solution

sanjay_shrestha
Contributor

aha.. add "search" keyword...
so... it would be like..

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" BRAND_NAME="*" | stats count as apicount by BRAND_NAME |sort + BRAND_NAME 
 |eventstats sum(apicount) as apicountsum
 |eval brand_Cost = apicount * [search index=aws-bill Subscription="shared-identity" | stats sum(UnBlendedCost) as idxcost| rename idxcost as query | fields query | head 1 ]/apicountsum

View solution in original post

sanjay_shrestha
Contributor

aha.. add "search" keyword...
so... it would be like..

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" BRAND_NAME="*" | stats count as apicount by BRAND_NAME |sort + BRAND_NAME 
 |eventstats sum(apicount) as apicountsum
 |eval brand_Cost = apicount * [search index=aws-bill Subscription="shared-identity" | stats sum(UnBlendedCost) as idxcost| rename idxcost as query | fields query | head 1 ]/apicountsum

dhavamanis
Builder

Thank you so much. i just altered the query like this and its working fine.

index="idxweblogaws" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" BRAND_NAME="*" | stats count as apicount by BRAND_NAME |sort + BRAND_NAME
|eventstats sum(apicount) as apicountsum
|eval idxcost1 = [search index=aws-bill Subscription="shared-identity" | stats sum(UnBlendedCost) as idxcost| rename idxcost as query | fields query | head 1 ] | eval brand_Cost = round(apicount * (round(idxcost1,4) /apicountsum), 4)

dhavamanis
Builder

Now i am getting this error,

"Error in 'eval' command: The 'not' function is unsupported or undefined."

0 Karma

sanjay_shrestha
Contributor

I tried similar query:

index=_audit|stats count AS C by user|eventstats sum(C) as tot 
| eval res = C * [search index=_audit|stats dc(user) as result
| rename result as query | fields query | head 1]/tot

and it worked. You can refer to same idea.

0 Karma

sanjay_shrestha
Contributor

Is there any typo?

0 Karma

sanjay_shrestha
Contributor

You can try like this:

index="idxweblog" source="/opt/apache2/logs/idxapi.nbcuni.com-access_log" BRAND_NAME="*" | stats count as apicount by BRAND_NAME |sort + BRAND_NAME 
|eventstats sum(apicount) as apicountsum
|eval brand_Cost = apicount * [index=aws-bill Subscription="shared-identity" | stats sum(UnBlendedCost) as idxcost| rename idxcost as query | fields query | head 1 ]/apicountsum
0 Karma

dhavamanis
Builder

i am getting error like "Unknown search command 'index'."

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...