# Question on function score script

**URL:** https://discuss.elastic.co/t/question-on-function-score-script/15773
**Category:** Elasticsearch
**Created:** [February 13, 2014, 7:54am UTC](https://discuss.elastic.co/t/question-on-function-score-script/15773 "2014-02-13T07:54:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [February 13, 2014, 7:54am UTC](https://discuss.elastic.co/t/question-on-function-score-script/15773/1 "2014-02-13T07:54:11Z")

</div>

Hi everyone - I am facing an error when executing a function score query  
and just wanted to get your comments on the same.

This is the script:  
"script\_score": {  
"script": "doc['boostValue'].value \>0 ? ( \_score \*  
doc['boostValue'].value ) : \_score"  
}

It primarily says that if the boostValue is positive, then multiply \_score  
by it else use \_score as is. The error I get is below:

reason: QueryPhaseExecutionException[[index\_type\_1][0]: query[function  
score (filtered(website:bank  
name:bank)-\>cache(region:US),function=script[doc['boostValue'].value \>0 ? (  
\_score \* doc['boostValue'].value ) : \_score], params  
[null])],from[0],size[5]: Query Failed [Failed to execute main query]];  
nested: PropertyAccessException[[Error: could not access: value; in class:  
org.elasticsearch.index.fielddata.ScriptDocValues$Empty] [Near : {...  
doc['boostValue'].value \>0 ? ( ....}] ^ [Line: 1, Column: 1]];

Any thoughts?

-Amit.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2B%2BxmQV19xGzKs0NzP2Dufx1S%3DDPeiH018q3itPRxjVxA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2B%2BxmQV19xGzKs0NzP2Dufx1S%3DDPeiH018q3itPRxjVxA%40mail.gmail.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: [February 13, 2014, 9:26am UTC](https://discuss.elastic.co/t/question-on-function-score-script/15773/2 "2014-02-13T09:26:33Z")

</div>

Hey,

most likely some document which matched your query does not contain the  
field boostValue...

--Alex

On Thu, Feb 13, 2014 at 8:54 AM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> Hi everyone - I am facing an error when executing a function score query  
> and just wanted to get your comments on the same.
> 
> This is the script:  
> "script\_score": {  
> "script": "doc['boostValue'].value \>0 ? ( \_score \*  
> doc['boostValue'].value ) : \_score"  
> }
> 
> It primarily says that if the boostValue is positive, then multiply \_score  
> by it else use \_score as is. The error I get is below:
> 
> reason: QueryPhaseExecutionException[[index\_type\_1][0]: query[function  
> score (filtered(website:bank  
> name:bank)-\>cache(region:US),function=script[doc['boostValue'].value \>0 ? (  
> \_score \* doc['boostValue'].value ) : \_score], params  
> [null])],from[0],size[5]: Query Failed [Failed to execute main query]];  
> nested: PropertyAccessException[[Error: could not access: value; in class:  
> org.elasticsearch.index.fielddata.ScriptDocValues$Empty] [Near : {...  
> doc['boostValue'].value \>0 ? ( ....}] ^ [Line: 1, Column: 1]];
> 
> Any thoughts?
> 
> -Amit.
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2B%2BxmQV19xGzKs0NzP2Dufx1S%3DDPeiH018q3itPRxjVxA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2B%2BxmQV19xGzKs0NzP2Dufx1S%3DDPeiH018q3itPRxjVxA%40mail.gmail.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9u1%3DpNqZG\_-yrfHia3Y6hOG\_6HSxH2gVvtZiEovxP6yw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9u1%3DpNqZG_-yrfHia3Y6hOG_6HSxH2gVvtZiEovxP6yw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)
#### Post date: [February 13, 2014, 1:02pm UTC](https://discuss.elastic.co/t/question-on-function-score-script/15773/3 "2014-02-13T13:02:01Z")

</div>

And you can test for it if needed:

doc['boostValue'].isEmpty()

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/267ee0ce-b349-4a75-ae8d-c43d40ffc1d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/267ee0ce-b349-4a75-ae8d-c43d40ffc1d4%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [February 14, 2014, 3:55am UTC](https://discuss.elastic.co/t/question-on-function-score-script/15773/4 "2014-02-14T03:55:02Z")

</div>

thanks Alex and Binh. I tried with isEmpty() check and it worked fine.

-Amit.

On Thu, Feb 13, 2014 at 5:02 AM, Binh Ly [binh@hibalo.com](mailto:binh@hibalo.com) wrote:

> And you can test for it if needed:
> 
> doc['boostValue'].isEmpty()
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/267ee0ce-b349-4a75-ae8d-c43d40ffc1d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/267ee0ce-b349-4a75-ae8d-c43d40ffc1d4%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAOGaQK4ixbPfBoxQQoEvt26G64N4PkbLndYJOCRGgW%3DV2SH6w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQK4ixbPfBoxQQoEvt26G64N4PkbLndYJOCRGgW%3DV2SH6w%40mail.gmail.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, 1:50am UTC](https://discuss.elastic.co/t/question-on-function-score-script/15773/5 "2017-07-06T01:50:18Z")

</div>


