Problem with new script

Also add a space between the variable and the /

Hello,

I made changes and am sending printscreen of an error. It seems that systems sees the totalGood as 0 for some reason.

Thank you...sorry for not replying right away but max reply limit was reached yesterday...

Hey, if at least one document in your index doesnt have value for the actual quantity or is 0 then it will fail. You can make a check and do the division if the value exists and is not 0

I see...can you give me some hint on how to do that?

Thanks.

It seems like the error gets thrown before it even executes the script?

Hello,

I am not sure...this is what the error description says.

What your coworker suggested is to make a check and do the division if the value exists and is not 0 but I am not sure how to do that.

Can you help me out with this?

Yes, the failure seems to be a division by zero, according to that last error message.
Can you, just for testing, add a 1 to the second value?
Or just print out the bare values and see if it is zero.

Or try to divide it by a constant, like 2.

is this what you meant?

..if yes...then the error is that it cannot find totalGood...

Yes. That is very odd, since returning TotalGood in your first example was working, correct?

Unfortunately, I can't find a good doco covering painless scripting. I find it rather painful instead!

Yes, totalGood script works w/o any problems.

@Valerija this one fails because you removed the definition of the totalGood. If you add this line again in your script then it wont fail.

About the check to see if there is null or zero it should be a simple if statement.

Something like

def totalGood = doc['actualQuantity'].value - doc['failureQuantity'].value;

if (doc['actualQuantity'].value != null || doc['actualQuantity'].value != 0) {
   return totalGood / doc['actualQuantity'].value; 
} else {
    // return what makes sense here if the doc['actualQuantity'] does not exist
    return totalGood;
}

My script might have typos, please ensure that I have the fields names correctly

Hello @Stratoula_Kalafateli thank you so much for having patience with me...very very much. I am totally new to this tool and even simple if statement in Kibana is new to me...

Just to let you know that the script works now...I changed just one thing in the solution you provided and it works:

def totalGood = doc['actualQuantity'].value - doc['failureQuantity'].value;
if (doc['actualQuantity'].value != null && doc['actualQuantity'].value != 0) {
return totalGood / doc['actualQuantity'].value;
} else {
return null;
}

thank you once again a lot! :slight_smile:

2 Likes

I am happy we made this work :slight_smile:

2 Likes

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