Splunk Search

Why are fields returning true for both isNum() and isStr() ?

rolaso
Explorer

Hi,

I want to setup a search to alarm me if a field ever changes its nature. To play around, I chose the year field in one of our indexes. This field appears to be numeric.

field k="date_year" c="20" nc="20" dc="1" exact="1" relevant="0"

All 20 counts are numeric, hence it should be numeric.

I would expect this simple search to have isNum=true and isStr=false for all fields:

index=foo
| eval isStr= if(isstr(date_year),"true","false")
| eval isNum= if(isnum(date_year),"true","false")
| table isNum,isStr, date_year

But this is what I get:

isNum isStr date_year
true true 2014
true true 2014
true true 2014

I have done some research, and I can't find any posts about this behaviour. Can someone explain to me why this is happening?

Many thanks!

R

0 Karma
1 Solution

ppablo
Retired

Hi @rolaso

I think the reason isStr is returning "true" is because numeric values are also considered strings. I was just looking through Splunk documentation and found this:

"Numbers, for example, are strings that contain the number. For example, a field containing a value of the number 10 contains the characters 1 and 0: "10""

The date_year field will always be a number, so 2014 could be seen as containing the characters 2, 0, 1, 4: "2014", so it makes sense that | eval isStr= if(isstr(date_year),"true","false") would return "true".

View solution in original post

ppablo
Retired

Hi @rolaso

I think the reason isStr is returning "true" is because numeric values are also considered strings. I was just looking through Splunk documentation and found this:

"Numbers, for example, are strings that contain the number. For example, a field containing a value of the number 10 contains the characters 1 and 0: "10""

The date_year field will always be a number, so 2014 could be seen as containing the characters 2, 0, 1, 4: "2014", so it makes sense that | eval isStr= if(isstr(date_year),"true","false") would return "true".

weidertc
Communicator

Is this a claim that isnum() and isstr() are deprecated?  This was working up until recently.  I've been scratching my head for hours trying to fix my dashboard.

If this is the case then there needs to be a way to find out if a string containing only numbers is indeed only numbers.

0 Karma

rolaso
Explorer

Thank you for your reply, it makes perfect sense.

0 Karma

Nikobobinus
Engager

Under which scenarios does isstr return false then other than empty/null?

0 Karma

ppablo
Retired

No problem @rolaso glad I could clarify.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...