Empty Values in DateTimeStamp - Ignore Empty Values & Perform Calculation

Hi All,

Ver: 7.11 (Painless script)

  1. I have datetimestamp fields in number type, to convert into date format i have used doc['actualdatetimestamp'].value with the default format in painless script it worked

Need Help in Two Questions Please:

  1. Now i want to subtract two fields doc['targetdatetimestamp'].value - doc['actualdatetimestamp'].value, it is giving me errors because of some the documents are blank in doc['actualdatetimestamp'].value, how to ignore blank and proceed to calculation

  2. Now a product is been developed and deployed in production,
    -i need to find out if the product is deployed on or before the doc['expecteddate'] against doc['actualdate'],
    Case1: if it is deployed on/before doc['expecteddate'] than it will be 100%,
    Case2: If it is deployed 1 day after doc['expecteddate'] than it will be 80%

Kindly provide your valuable suggestion, your suggestions would really help me since i am beginner in KIBANA.

Stay Safe !


Use an if statement.
if there is no value, calculate with 0.

Use an if statement.
if the difference is zero/negative, return 80%. else return 100%

Hi Clerk,

Kindly correct me if the below script is right? this is my first script not sure if it's works, please help me here, much appreciate your time here.

doc['targetdatetimestamp'].value - doc['actualdatetimestamp'].value
if (doc['actualdatetimestamp']).empty {
return "0";

if doc['expecteddate'].value - doc['actualdate'].value <0 {
return "80%";
} else if doc['expecteddate'].value - doc['actualdate'].value >= 0 {
return "100%";

80/100 % should be number type

Looks OK.
Just check if the document is empty as the first condition.

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