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
Super Champion

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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...