# About scripting elasticsearch with plugin lang-javascript

**URL:** <https://discuss.elastic.co/t/about-scripting-elasticsearch-with-plugin-lang-javascript/8183>\
**Category:** Elasticsearch\
**Created:** [June 21, 2012, 2:49pm UTC](https://discuss.elastic.co/t/about-scripting-elasticsearch-with-plugin-lang-javascript/8183 "2012-06-21T14:49:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkcr2d2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gkcr2d2/32/2836_2.png) [@gkcr2d2](https://discuss.elastic.co/u/gkcr2d2)\
**Post date:** [June 21, 2012, 2:49pm UTC](https://discuss.elastic.co/t/about-scripting-elasticsearch-with-plugin-lang-javascript/8183/1 "2012-06-21T14:49:03Z")

</div>

Hello,

I try to query with custom score (with param lang =\> js)  
But, I didn't find documentation about the way to realise the script (acced  
to the \_source values, modify score etc.)

The score value that i need to personalize depends on the value of one  
field :  
if (myfield == '1234') {  
score += 10;  
} else if (myfield == '456' )  
{  
score += 20;  
}

Thank you for your help.

Best regards,

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [June 22, 2012, 8:28pm UTC](https://discuss.elastic.co/t/about-scripting-elasticsearch-with-plugin-lang-javascript/8183/2 "2012-06-22T20:28:06Z")

</div>

It's the same as with mvel. You can find details  
in [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/modules/scripting.html)

if (\_source['myfield'] == '1234') {  
\_score + 10;  
} else if (\_source['myfield'] == '456') {  
\_score + 20;  
} else {  
\_score;  
}

On Thursday, June 21, 2012 10:49:03 AM UTC-4, gkcr2d2 wrote:

> Hello,
> 
> I try to query with custom score (with param lang =\> js)  
> But, I didn't find documentation about the way to realise the script  
> (acced to the \_source values, modify score etc.)
> 
> The score value that i need to personalize depends on the value of one  
> field :  
> if (myfield == '1234') {  
> score += 10;  
> } else if (myfield == '456' )  
> {  
> score += 20;  
> }
> 
> Thank you for your help.
> 
> Best regards,

---

<div class="post-metadata">

**Author:** ![gkcr2d2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gkcr2d2/32/2836_2.png) [@gkcr2d2](https://discuss.elastic.co/u/gkcr2d2)\
**Post date:** [June 22, 2012, 8:42pm UTC](https://discuss.elastic.co/t/about-scripting-elasticsearch-with-plugin-lang-javascript/8183/3 "2012-06-22T20:42:08Z")

</div>

Thank you !

Le vendredi 22 juin 2012 22:28:06 UTC+2, Igor Motov a écrit :

> It's the same as with mvel. You can find details in  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/modules/scripting.html)
> 
> if (\_source['myfield'] == '1234') {  
> \_score + 10;  
> } else if (\_source['myfield'] == '456') {  
> \_score + 20;  
> } else {  
> \_score;  
> }
> 
> On Thursday, June 21, 2012 10:49:03 AM UTC-4, gkcr2d2 wrote:
> 
> > Hello,
> > 
> > I try to query with custom score (with param lang =\> js)  
> > But, I didn't find documentation about the way to realise the script  
> > (acced to the \_source values, modify score etc.)
> > 
> > The score value that i need to personalize depends on the value of one  
> > field :  
> > if (myfield == '1234') {  
> > score += 10;  
> > } else if (myfield == '456' )  
> > {  
> > score += 20;  
> > }
> > 
> > Thank you for your help.
> > 
> > Best regards,

---

<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, 3:22am UTC](https://discuss.elastic.co/t/about-scripting-elasticsearch-with-plugin-lang-javascript/8183/4 "2017-07-06T03:22:52Z")

</div>


