# Question on script scoring

**URL:** https://discuss.elastic.co/t/question-on-script-scoring/16118
**Category:** Elasticsearch
**Created:** [March 3, 2014, 7:51pm UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118 "2014-03-03T19:51:32Z")
**Posts on this page:** 9
**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: [March 3, 2014, 7:51pm UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/1 "2014-03-03T19:51:32Z")

</div>

Hi everyone - Since we were recommended to move away from using "\_boost" in  
the document, we have been trying to switch over to using custom scoring  
(script\_score).

We have a float value called boostValue (of type float) in the document we  
are using the following script to boost the score of matched document.  
However there seems to be no change in the generated score.

Any idea what might be wrong with this script?

"script\_score": {  
"script": "doc['boostValue'].empty || (doc['boostValue'].value \<=  
0) ? \_score : (doc['boostValue'].value \* \_score)"  
}

-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%2Bz3xBH2CkDeWNyc1Vtcku03VQPo6SjKTpG5dFwJtqTpA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2Bz3xBH2CkDeWNyc1Vtcku03VQPo6SjKTpG5dFwJtqTpA%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\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [March 3, 2014, 9:03pm UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/2 "2014-03-03T21:03:30Z")

</div>

Are you using the function\_score query in 1.0? If so, can you show your  
full query? 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%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: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [March 3, 2014, 9:08pm UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/3 "2014-03-03T21:08:57Z")

</div>

It could be that the precedence of || ? : is not what you expect. I've run  
into issues with that in mvel before. Try using parentheses to make the  
script unambiguous

clint

On 3 March 2014 20:51, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> Hi everyone - Since we were recommended to move away from using "\_boost"  
> in the document, we have been trying to switch over to using custom scoring  
> (script\_score).
> 
> We have a float value called boostValue (of type float) in the document we  
> are using the following script to boost the score of matched document.  
> However there seems to be no change in the generated score.
> 
> Any idea what might be wrong with this script?
> 
> "script\_score": {  
> "script": "doc['boostValue'].empty || (doc['boostValue'].value \<=  
> 0) ? \_score : (doc['boostValue'].value \* \_score)"  
> }
> 
> -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%2Bz3xBH2CkDeWNyc1Vtcku03VQPo6SjKTpG5dFwJtqTpA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2Bz3xBH2CkDeWNyc1Vtcku03VQPo6SjKTpG5dFwJtqTpA%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/CAPt3XKQwi5rgu-oy3P3k4QanEr33N4GYYxwRPf-2bCYNXb46Vw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKQwi5rgu-oy3P3k4QanEr33N4GYYxwRPf-2bCYNXb46Vw%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: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [March 3, 2014, 9:14pm UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/4 "2014-03-03T21:14:23Z")

</div>

First, .empty is super slow right now:

> <https://github.com/elastic/elasticsearch/issues/5086>
>
> This happens when you use \`.empty\` to check if a field is empty and it actually …is empty. I've made a gist to reproduce it: https://gist.github.com/nik9000/8937202
> 
> High level:
> 1. Hit ~1 million documents with a script score.
> 2. Do something like \`(doc\['foo'\].empty ? 0 : doc\['foo'\].value) \* doc\['bar'\]\`. The \`.empty\` is the key here.
> 3. If most of the documents don't have a \`foo\` then this is really slow. Like, two seconds slow.
> 4. Instead, switch to this \`(doc\['foo'\].isEmpty() ? 0 : doc\['foo'\].value) \* doc\['bar'\]\`. That is faster. .36 seconds or so. Not super speedy, but much better.
> 
> I'm not completely sure what is happening but my guess is that the MVEL optimizer is optimizing .empty is a call to .isEmpty on an instance of either ScriptDocValues or ScriptDocValues.Empty. When it hits the wrong one it recovers by catching an IllegalArgumentException thrown by the JVM and then does some munging. The act of filling in the stack trace for that IllegalArgumentException is really really really slow. So slow, I see it in the hot threads: https://gist.github.com/nik9000/8937335 .
> 
> Workaround: use \`.isEmpty()\` instead of \`.empty\`.
> 
> I'm not sure what the fix ought to be.

Second, be paranoid about order of operations with MVEL. I'd play around  
with parrens until it worked.  
Third, multiply is the default boost mode so you can just leave out the  
\_score which might make the MVEL simpler.

On Mon, Mar 3, 2014 at 4:03 PM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:

> Are you using the function\_score query in 1.0? If so, can you show your  
> full query? 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%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/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%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: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [March 4, 2014, 2:56am UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/5 "2014-03-04T02:56:01Z")

</div>

Thanks much Nikolas and Clint.

@_Binh_ - Below is my complete query:

{  
"from": 0,  
"size": 15,  
"query": {  
"function\_score": {  
"query": {  
"filtered": {  
"query": {  
"simple\_query\_string": {  
"query": "some query",  
"fields": [  
"searchKeywords",  
"website",  
"name^2.0"  
],  
"default\_operator": "and"  
}  
},  
"filter": {  
"term": {  
"region": "some region"  
}  
}  
}  
},  
"script\_score": {  
"script": "doc['boostValue'].empty || (doc['boostValue'].value \<=  
0) ? \_score : doc['boostValue'].value \* \_score"  
}  
}  
},  
"explain": false  
}

-Amit.

On Mon, Mar 3, 2014 at 1:14 PM, Nikolas Everett [nik9000@gmail.com](mailto:nik9000@gmail.com) wrote:

> First, .empty is super slow right now:  
> [In MVEL .empty can be way way way slower then .isEmpty() · Issue #5086 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/5086)  
> Second, be paranoid about order of operations with MVEL. I'd play around  
> with parrens until it worked.  
> Third, multiply is the default boost mode so you can just leave out the  
> \_score which might make the MVEL simpler.
> 
> On Mon, Mar 3, 2014 at 4:03 PM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:
> 
> > Are you using the function\_score query in 1.0? If so, can you show your  
> > full query? 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%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/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%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/CAAOGaQ%2BzgC%3D\_mLbRVu%3DDfS1B7VPoRmcKufm8EH7Hv-m93zcMXw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2BzgC%3D_mLbRVu%3DDfS1B7VPoRmcKufm8EH7Hv-m93zcMXw%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: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [March 4, 2014, 3:13am UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/6 "2014-03-04T03:13:22Z")

</div>

and yes I am running 1.0.0.

@Nikolas and Clint - I tried your suggestions and played with parenthesis  
but didnt have any luck. anything else I am missing?

thanks much for your help!

-Amit.

On Mon, Mar 3, 2014 at 6:56 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> Thanks much Nikolas and Clint.
> 
> @_Binh_ - Below is my complete query:
> 
> {  
> "from": 0,  
> "size": 15,  
> "query": {  
> "function\_score": {  
> "query": {  
> "filtered": {  
> "query": {  
> "simple\_query\_string": {  
> "query": "some query",  
> "fields": [  
> "searchKeywords",  
> "website",  
> "name^2.0"  
> ],  
> "default\_operator": "and"  
> }  
> },  
> "filter": {  
> "term": {  
> "region": "some region"  
> }  
> }  
> }  
> },  
> "script\_score": {  
> "script": "doc['boostValue'].empty || (doc['boostValue'].value \<=  
> 0) ? \_score : doc['boostValue'].value \* \_score"  
> }  
> }  
> },  
> "explain": false  
> }
> 
> -Amit.
> 
> On Mon, Mar 3, 2014 at 1:14 PM, Nikolas Everett [nik9000@gmail.com](mailto:nik9000@gmail.com) wrote:
> 
> > First, .empty is super slow right now:  
> > [In MVEL .empty can be way way way slower then .isEmpty() · Issue #5086 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/5086)  
> > Second, be paranoid about order of operations with MVEL. I'd play around  
> > with parrens until it worked.  
> > Third, multiply is the default boost mode so you can just leave out the  
> > \_score which might make the MVEL simpler.
> > 
> > On Mon, Mar 3, 2014 at 4:03 PM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:
> > 
> > > Are you using the function\_score query in 1.0? If so, can you show your  
> > > full query? 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).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%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/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%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/CAAOGaQL1kAXmyo5g%3DcC1x%3DyL789SAdYTfJD9FMOeG0yWD%2BCs2w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQL1kAXmyo5g%3DcC1x%3DyL789SAdYTfJD9FMOeG0yWD%2BCs2w%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: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [March 6, 2014, 5:36pm UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/7 "2014-03-06T17:36:49Z")

</div>

hello everyone - first of all my apology for following up on this soon  
enough.

wondering if anyone has got things working with script scoring and can  
share their script, or help me with what might be wrong with the below  
script.

"script\_score": {  
"script": "doc['boostValue'].empty || (doc['boostValue'].value \<=  
0) ? \_score : doc['boostValue'].value \* \_score"  
}

-Amit.

On Mon, Mar 3, 2014 at 7:13 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> and yes I am running 1.0.0.
> 
> @Nikolas and Clint - I tried your suggestions and played with parenthesis  
> but didnt have any luck. anything else I am missing?
> 
> thanks much for your help!
> 
> -Amit.
> 
> On Mon, Mar 3, 2014 at 6:56 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:
> 
> > Thanks much Nikolas and Clint.
> > 
> > @_Binh_ - Below is my complete query:
> > 
> > {  
> > "from": 0,  
> > "size": 15,  
> > "query": {  
> > "function\_score": {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "simple\_query\_string": {  
> > "query": "some query",  
> > "fields": [  
> > "searchKeywords",  
> > "website",  
> > "name^2.0"  
> > ],  
> > "default\_operator": "and"  
> > }  
> > },  
> > "filter": {  
> > "term": {  
> > "region": "some region"  
> > }  
> > }  
> > }  
> > },  
> > "script\_score": {  
> > "script": "doc['boostValue'].empty || (doc['boostValue'].value  
> > \<= 0) ? \_score : doc['boostValue'].value \* \_score"  
> > }  
> > }  
> > },  
> > "explain": false  
> > }
> > 
> > -Amit.
> > 
> > On Mon, Mar 3, 2014 at 1:14 PM, Nikolas Everett [nik9000@gmail.com](mailto:nik9000@gmail.com)wrote:
> > 
> > > First, .empty is super slow right now:  
> > > [In MVEL .empty can be way way way slower then .isEmpty() · Issue #5086 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/5086)  
> > > Second, be paranoid about order of operations with MVEL. I'd play  
> > > around with parrens until it worked.  
> > > Third, multiply is the default boost mode so you can just leave out the  
> > > \_score which might make the MVEL simpler.
> > > 
> > > On Mon, Mar 3, 2014 at 4:03 PM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:
> > > 
> > > > Are you using the function\_score query in 1.0? If so, can you show your  
> > > > full query? 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).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%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/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%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/CAAOGaQL5P3u3Qx9OX7kQEdT1DRxvkNCow8XgLYdVeeB8c0F0bA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQL5P3u3Qx9OX7kQEdT1DRxvkNCow8XgLYdVeeB8c0F0bA%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: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [March 14, 2014, 5:31am UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/8 "2014-03-14T05:31:42Z")

</div>

Hi all - After a good amount of debugging, I figured out the problem and  
wanted to share with this group. I had defined the mapping for 'boostValue'  
wherein I had "index=no", my bad 🙂

After I changed mapping to "index": "not\_analyzed" for this boost field, it  
worked fine.

-Amit.

On Thu, Mar 6, 2014 at 9:36 AM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> hello everyone - first of all my apology for following up on this soon  
> enough.
> 
> wondering if anyone has got things working with script scoring and can  
> share their script, or help me with what might be wrong with the below  
> script.
> 
> "script\_score": {  
> "script": "doc['boostValue'].empty || (doc['boostValue'].value \<=  
> 0) ? \_score : doc['boostValue'].value \* \_score"  
> }
> 
> -Amit.
> 
> On Mon, Mar 3, 2014 at 7:13 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:
> 
> > and yes I am running 1.0.0.
> > 
> > @Nikolas and Clint - I tried your suggestions and played with parenthesis  
> > but didnt have any luck. anything else I am missing?
> > 
> > thanks much for your help!
> > 
> > -Amit.
> > 
> > On Mon, Mar 3, 2014 at 6:56 PM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:
> > 
> > > Thanks much Nikolas and Clint.
> > > 
> > > @_Binh_ - Below is my complete query:
> > > 
> > > {  
> > > "from": 0,  
> > > "size": 15,  
> > > "query": {  
> > > "function\_score": {  
> > > "query": {  
> > > "filtered": {  
> > > "query": {  
> > > "simple\_query\_string": {  
> > > "query": "some query",  
> > > "fields": [  
> > > "searchKeywords",  
> > > "website",  
> > > "name^2.0"  
> > > ],  
> > > "default\_operator": "and"  
> > > }  
> > > },  
> > > "filter": {  
> > > "term": {  
> > > "region": "some region"  
> > > }  
> > > }  
> > > }  
> > > },  
> > > "script\_score": {  
> > > "script": "doc['boostValue'].empty || (doc['boostValue'].value  
> > > \<= 0) ? \_score : doc['boostValue'].value \* \_score"  
> > > }  
> > > }  
> > > },  
> > > "explain": false  
> > > }
> > > 
> > > -Amit.
> > > 
> > > On Mon, Mar 3, 2014 at 1:14 PM, Nikolas Everett [nik9000@gmail.com](mailto:nik9000@gmail.com)wrote:
> > > 
> > > > First, .empty is super slow right now:  
> > > > [In MVEL .empty can be way way way slower then .isEmpty() · Issue #5086 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/5086)  
> > > > Second, be paranoid about order of operations with MVEL. I'd play  
> > > > around with parrens until it worked.  
> > > > Third, multiply is the default boost mode so you can just leave out the  
> > > > \_score which might make the MVEL simpler.
> > > > 
> > > > On Mon, Mar 3, 2014 at 4:03 PM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:
> > > > 
> > > > > Are you using the function\_score query in 1.0? If so, can you show  
> > > > > your full query? 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).  
> > > > > To view this discussion on the web visit  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7452f652-f9b0-424c-a3ec-3e991afbd42f%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/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd3tgEtVD4Lt6Ce3i225M2ZHq%2BuBDc1Zsrh3xH6fKYtSLw%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/CAAOGaQJEE4sesCrGuVfKcXqo8qOV6jONr%3D9NRfvnx4N0WSytfg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQJEE4sesCrGuVfKcXqo8qOV6jONr%3D9NRfvnx4N0WSytfg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:43am UTC](https://discuss.elastic.co/t/question-on-script-scoring/16118/9 "2017-07-06T01:43:16Z")

</div>


