# Testing for NaN with MVEL with custom script?

**URL:** <https://discuss.elastic.co/t/testing-for-nan-with-mvel-with-custom-script/11955>\
**Category:** Elasticsearch\
**Created:** [May 14, 2013, 1:00pm UTC](https://discuss.elastic.co/t/testing-for-nan-with-mvel-with-custom-script/11955 "2013-05-14T13:00:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [May 14, 2013, 1:00pm UTC](https://discuss.elastic.co/t/testing-for-nan-with-mvel-with-custom-script/11955/1 "2013-05-14T13:00:30Z")

</div>

When one search term started bombing, I discovered that one of my documents  
somehow must be returning an NaN for one of the custom score scripts  
fields. I was using the ternary operator already for emptiness:

"script": "\_score +  
(doc['custom\_booster'].empty?0.0:doc['custom\_booster].value)"

However, empty does not cover the case of NaN.

I've tried using variations on the MVEL "is" and "instanceOf" decimal but I  
don't know if or how those are supported as every variation throws an  
error.

I did notice this issue:

> <https://github.com/elastic/elasticsearch/issues/2426>

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [May 14, 2013, 1:40pm UTC](https://discuss.elastic.co/t/testing-for-nan-with-mvel-with-custom-script/11955/2 "2013-05-14T13:40:16Z")

</div>

Hey

have you tried  
doc['custom\_booster'].value instanceof Number

You may want to think about index time boosting (although not that  
flexible) if you are using this script all the time.

--Alex

On Tue, May 14, 2013 at 3:00 PM, Justin Treher [jtreher@gmail.com](mailto:jtreher@gmail.com) wrote:

> When one search term started bombing, I discovered that one of my  
> documents somehow must be returning an NaN for one of the custom score  
> scripts fields. I was using the ternary operator already for emptiness:
> 
> "script": "\_score +  
> (doc['custom\_booster'].empty?0.0:doc['custom\_booster].value)"
> 
> However, empty does not cover the case of NaN.
> 
> I've tried using variations on the MVEL "is" and "instanceOf" decimal but  
> I don't know if or how those are supported as every variation throws an  
> error.
> 
> I did notice this issue:  
> [When script\_score script returns NaN, entire request fails with a confusing error message · Issue #2426 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2426)
> 
> Thanks!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 15, 2013, 9:25am UTC](https://discuss.elastic.co/t/testing-for-nan-with-mvel-with-custom-script/11955/3 "2013-05-15T09:25:14Z")

</div>

Hi Justin

What type is your 'custom\_booster' mapped as? If it is a number, I'd be  
interested to see what value is producing a NaN. Any chance you can  
reproduce?

clint

On Tue, May 14, 2013 at 3:40 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey
> 
> have you tried  
> doc['custom\_booster'].value instanceof Number
> 
> You may want to think about index time boosting (although not that  
> flexible) if you are using this script all the time.
> 
> --Alex
> 
> On Tue, May 14, 2013 at 3:00 PM, Justin Treher [jtreher@gmail.com](mailto:jtreher@gmail.com) wrote:
> 
> > When one search term started bombing, I discovered that one of my  
> > documents somehow must be returning an NaN for one of the custom score  
> > scripts fields. I was using the ternary operator already for emptiness:
> > 
> > "script": "\_score +  
> > (doc['custom\_booster'].empty?0.0:doc['custom\_booster].value)"
> > 
> > However, empty does not cover the case of NaN.
> > 
> > I've tried using variations on the MVEL "is" and "instanceOf" decimal but  
> > I don't know if or how those are supported as every variation throws an  
> > error.
> > 
> > I did notice this issue:  
> > [When script\_score script returns NaN, entire request fails with a confusing error message · Issue #2426 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2426)
> > 
> > Thanks!
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:36am UTC](https://discuss.elastic.co/t/testing-for-nan-with-mvel-with-custom-script/11955/4 "2017-07-06T02:36:39Z")

</div>


