Convert number to string


#1

Hello,
I have a number field ('response') with values ranging between 0-2. I need to do scripted field which converts these number to string values. 0=Bad, 1=OK, 2=Excellent. How do I do that?

I am trying:
if (doc['response'].value = 0) { return "Bad"; }
if (doc['response'].value = 1) { return "OK"; }
if (doc['resonnse'].value = 2) { return "Excellent"; }
return "";

However this is not working .
I get errors '...."compile error","script_stack":["if (doc .........lang":"painless","caused_by":{"type":"class_cast_exception","reason":"Cannot cast from [int] to [boolean]."}}}]},"status":500}......'_


(Archana ) #2

Hi jali,

I'm not a painless expert, but can you just try == instead of = in your if statements?


#3

And... it works! Thanks!!


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.