Splunk Search

How to rename fields only from a certain search (Search1) OR (Search 2)?

erikschubert
Engager

Hello everyone,

I have a search in the following format:

(index="index1" group=a) OR (index="index2" group=a)....

Later on in the search I want to rename the field host to splunkname, but only those found in events coming from the second "search". The problem ist that both "searches" return events with a field called host.

When I tried this, it didnt work:
(index="index1" group=a) OR (index="index2" group=a| rename host AS splunkname)

How could I solve this?

Labels (2)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @erikschubert,

you have to use eval if:

index="index1" group=a) OR (index="index2" group=a)....
| eval splunkname=if(index=indexB,host, splunkname)

you said that splunkname is equal to host for the second search but you didn't specified what's the value of splunkname for the first search, I supposed that there's this field, anyway take the approach to the problem and the general solution.

Ciao.

Giuseppe

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...