Splunk Search

How to add a new column to a row?

kdimaria
Communicator

I am trying to add a new column to a row that is a different search than the first search. Using append puts it in a new row but I want it in the same row.

So basically I have

index=a sourcetype=a | stats count as queue | eval Name="PA" | table Name queue | append [ search index=b sourcetype=b | stats count as count | eval Name="PA" | table Name count

So I'm getting data that correlates from two different sourcetypes and indexes but theres no field I can join on and I just want it on the same row. Name, queue and count on the same row.

0 Karma
1 Solution

kdimaria
Communicator

Nevermind. I found out using join with no field works.

index=a sourcetype=a | stats count as queue | eval Name="PA" | table Name queue count | join [ search index=b sourcetype=b | stats count as count] 

View solution in original post

kdimaria
Communicator

Nevermind. I found out using join with no field works.

index=a sourcetype=a | stats count as queue | eval Name="PA" | table Name queue count | join [ search index=b sourcetype=b | stats count as count] 

somesoni2
Revered Legend

Since both your searches return single row, you can also do these:

 index=a sourcetype=a | stats count as queue | eval Name="PA" | table Name queue count | appendcols [ search index=b sourcetype=b | stats count as count] 

OR

 index=a sourcetype=a | stats count as queue | eval Name="PA" | table Name queue count | eval count=[ search index=b sourcetype=b | stats count as search] 

As @adonio suggested, these merging both queries into one would be optimal solution, as compared to all of the above solution with subsearches.

adonio
Ultra Champion

hello there,

hope i understand the question correctly,
try conditional eval in stats:

(index=a sourcetype=a) OR (index=b sourcetype=b) 
| stats count(eval(sourcetype="a")) as queue count(eval(sourcetype=b)) as count
| eval Name="PA"
0 Karma

kdimaria
Communicator

uhh that might work but I found out just using join works.

0 Karma

adonio
Ultra Champion

join is expensive, better use stats when possible

0 Karma

kdimaria
Communicator

I don't think your solution will work because I'm grabbing different fields and not counting the sourcetype.

0 Karma
Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

New Release | Splunk Cloud Platform 10.1.2507

Hello Splunk Community!We are thrilled to announce the General Availability of Splunk Cloud Platform 10.1.2507 ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...