# Painless validation returning null giving exception

**URL:** <https://discuss.elastic.co/t/painless-validation-returning-null-giving-exception/189861>\
**Category:** Kibana\
**Created:** [July 10, 2019, 7:53pm UTC](https://discuss.elastic.co/t/painless-validation-returning-null-giving-exception/189861 "2019-07-10T19:53:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrunoSdeMenezes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brunosdemenezes/32/46413_2.png) [@BrunoSdeMenezes](https://discuss.elastic.co/u/BrunoSdeMenezes)\
**Post date:** [July 10, 2019, 7:53pm UTC](https://discuss.elastic.co/t/painless-validation-returning-null-giving-exception/189861/1 "2019-07-10T19:53:50Z")

</div>

Hello everyone,

I'm building a painless script for a scripted field, but when I do a check for null using size() (the validation method recommended for Kibana 7.1.0), I'm getting exception error:

`Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["... , retorna null\n return null;\n}"," ^---- HERE"],"script":"if (doc['obrigacao_prazo_cumprimento'].size() == 0){ // Se não houver prazo, retorna null\n return null;\n}","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"vv_106_tarefas","node":"EqfbZ7UtS8aorpsDs5pF_A","reason":{"type":"script_exception","reason":"compile error","script_stack":["... , retorna null\n return null;\n}"," ^---- HERE"],"script":"if (doc['obrigacao_prazo_cumprimento'].size() == 0){ // Se não houver prazo, retorna null\n return null;\n}","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"Cannot cast null to a primitive type [double]."}}}]},"status":400}`

This is the script:

```
if (doc['obrigacao_prazo_cumprimento'].size() == 0){ 
   return null;
}

```

There is more on the script, but this line is the first one and is breaking.

The field is a date and returns a number.

Can someone help me solve this?  
Thanks

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 10, 2019, 8:22pm UTC](https://discuss.elastic.co/t/painless-validation-returning-null-giving-exception/189861/2 "2019-07-10T20:22:45Z")

</div>

It might be easier to start with a really simple script and work from there.

What does the following script return?

```auto
if (doc['obrigacao_prazo_cumprimento'].size() == 0){ 
   return null;
}
return doc['obrigacao_prazo_cumprimento'].value

```

---

<div class="post-metadata">

**Author:** ![BrunoSdeMenezes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brunosdemenezes/32/46413_2.png) [@BrunoSdeMenezes](https://discuss.elastic.co/u/BrunoSdeMenezes)\
**Post date:** [July 11, 2019, 1:19pm UTC](https://discuss.elastic.co/t/painless-validation-returning-null-giving-exception/189861/3 "2019-07-11T13:19:01Z")

</div>

> [@Nathan\_Reese](#):
>
> if (doc['obrigacao\_prazo\_cumprimento'].size() == 0){ return null; } return doc['obrigacao\_prazo\_cumprimento'].value

Thanks... I've got here... It was a cache problem that wasn't updating the script.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 8, 2019, 1:25pm UTC](https://discuss.elastic.co/t/painless-validation-returning-null-giving-exception/189861/4 "2019-08-08T13:25:33Z")

</div>

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