Splunk Search

Why is my "eval field=if()" search returning TRUE or FALSE instead of a numeric value?

andrei1bc
Communicator

Hi.

I am trying to search across multiple indexes. The field I am looking for is Value (and has only numbers). This value must not contain any decimals, and in case the sourcetype is sourcetype1, then the value must be recalculated as (Value-100)*-1.

My search:

index=*  sourcetype="sourcetype1" OR source=source2 | eval Value=if(sourcetype="sourcetype1", Value=round(((Value-100)*-1), 0), Value=round(Value, 0))

The result I get is either True or False for the Value field. What am I doing wrong?

Thank you in advance.

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Your if command is returning comparisons instead of values. Try

index= sourcetype="sourcetype1" OR source=source2 | eval Value=if(sourcetype="sourcetype1", round(((Value-100)-1), 0), round(Value, 0))
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Your if command is returning comparisons instead of values. Try

index= sourcetype="sourcetype1" OR source=source2 | eval Value=if(sourcetype="sourcetype1", round(((Value-100)-1), 0), round(Value, 0))
---
If this reply helps you, Karma would be appreciated.

javiergn
SplunkTrust
SplunkTrust

I've just deleted my answer as @richgalloway already provided you with a valid one

0 Karma

andrei1bc
Communicator
  • forgot to mention that there is no event in any index that has the sourcetype=sourcetype1 and source=source2
  • sourcetype=sourcetype1 events are stored in index1
  • source=source2 events are stored in index2
  • searching by value and applying the same type of condition returns me the same TRUE / FALSE results
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...