# Interesting script field nuance on 0.14.2

**URL:** <https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769>\
**Category:** Elasticsearch\
**Created:** [January 12, 2011, 9:19pm UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769 "2011-01-12T21:19:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [January 12, 2011, 9:19pm UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769/1 "2011-01-12T21:19:23Z")

</div>

Hey,  
0.14.2 is looking good for us, The highlighting on source cut our  
indexes sizes in half, thanks!!!

One thing I noticed is that one of our custom script fields broke with  
this error:  
Error: statically-typed variable already defined in scope: value

The script was basically:  
String value = \_source[fieldName];  
// Return first x number of chars from the field

I guess the value variable is now defined by ES within the scripts  
execution context? Seems like an unlucky collision. My advice is for  
ES to prefix all the internal variables in that scope with something  
like esInternal.

The update to my script to fix is trivial and similar in the future  
can be avoided by using my own prefixing on my vars.

Thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [January 12, 2011, 9:36pm UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769/2 "2011-01-12T21:36:57Z")

</div>

Err... I think my analysis was off base. Still looking into what my  
problem is. Apologies for the noise.

On Jan 12, 2:19 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:

> Hey,  
> 0.14.2 is looking good for us, The highlighting on source cut our  
> indexes sizes in half, thanks!!!
> 
> One thing I noticed is that one of our custom script fields broke with  
> this error:  
> Error: statically-typed variable already defined in scope: value
> 
> The script was basically:  
> String value = \_source[fieldName];  
> // Return first x number of chars from the field
> 
> I guess the value variable is now defined by ES within the scripts  
> execution context? Seems like an unlucky collision. My advice is for  
> ES to prefix all the internal variables in that scope with something  
> like esInternal.
> 
> The update to my script to fix is trivial and similar in the future  
> can be avoided by using my own prefixing on my vars.
> 
> Thanks,  
> Paul

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [January 12, 2011, 10:06pm UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769/3 "2011-01-12T22:06:11Z")

</div>

Not sure exactly why, but this had to do with me using a variable  
within the context of a script. On 14.2 here this example fails:  
scriptBuilder.append("String test = "test";");  
scriptBuilder.append("return test.length();");

Don't get why, but I can work directly off the \_source variable, so  
that makes more sense anyways.

Thanks,  
Paul

On Jan 12, 2:36 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:

> Err... I think my analysis was off base. Still looking into what my  
> problem is. Apologies for the noise.
> 
> On Jan 12, 2:19 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> 
> > Hey,  
> > 0.14.2 is looking good for us, The highlighting on source cut our  
> > indexes sizes in half, thanks!!!
> 
> > One thing I noticed is that one of our custom script fields broke with  
> > this error:  
> > Error: statically-typed variable already defined in scope: value
> 
> > The script was basically:  
> > String value = \_source[fieldName];  
> > // Return first x number of chars from the field
> 
> > I guess the value variable is now defined by ES within the scripts  
> > execution context? Seems like an unlucky collision. My advice is for  
> > ES to prefix all the internal variables in that scope with something  
> > like esInternal.
> 
> > The update to my script to fix is trivial and similar in the future  
> > can be avoided by using my own prefixing on my vars.
> 
> > Thanks,  
> > Paul

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 12, 2011, 10:25pm UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769/4 "2011-01-12T22:25:57Z")

</div>

Can you recreate the regression with curl? I will check with mvel.  
On Thursday, January 13, 2011 at 12:06 AM, Paul wrote:

> Not sure exactly why, but this had to do with me using a variable  
> within the context of a script. On 14.2 here this example fails:  
> scriptBuilder.append("String test = "test";");  
> scriptBuilder.append("return test.length();");
> 
> Don't get why, but I can work directly off the \_source variable, so  
> that makes more sense anyways.
> 
> Thanks,  
> Paul
> 
> On Jan 12, 2:36 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> 
> > Err... I think my analysis was off base. Still looking into what my  
> > problem is. Apologies for the noise.
> > 
> > On Jan 12, 2:19 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> > 
> > > Hey,  
> > > 0.14.2 is looking good for us, The highlighting on source cut our  
> > > indexes sizes in half, thanks!!!
> > 
> > > One thing I noticed is that one of our custom script fields broke with  
> > > this error:  
> > > Error: statically-typed variable already defined in scope: value
> > 
> > > The script was basically:  
> > > String value = \_source[fieldName];  
> > > // Return first x number of chars from the field
> > 
> > > I guess the value variable is now defined by ES within the scripts  
> > > execution context? Seems like an unlucky collision. My advice is for  
> > > ES to prefix all the internal variables in that scope with something  
> > > like esInternal.
> > 
> > > The update to my script to fix is trivial and similar in the future  
> > > can be avoided by using my own prefixing on my vars.
> > 
> > > Thanks,  
> > > Paul

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [January 19, 2011, 6:21pm UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769/5 "2011-01-19T18:21:07Z")

</div>

Hey Shay,  
This simple example should reproduce the issue for you on 0.14.2:

> <https://gist.github.com/ppearcy/786580>

Thanks!

On Jan 12, 3:25 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Can you recreate the regression with curl? I will check with mvel.
> 
> On Thursday, January 13, 2011 at 12:06 AM, Paul wrote:
> 
> > Not sure exactly why, but this had to do with me using a variable  
> > within the context of a script. On 14.2 here this example fails:  
> > scriptBuilder.append("String test = "test";");  
> > scriptBuilder.append("return test.length();");
> 
> > Don't get why, but I can work directly off the \_source variable, so  
> > that makes more sense anyways.
> 
> > Thanks,  
> > Paul
> 
> > On Jan 12, 2:36 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> 
> > > Err... I think my analysis was off base. Still looking into what my  
> > > problem is. Apologies for the noise.
> 
> > > On Jan 12, 2:19 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> 
> > > > Hey,  
> > > > 0.14.2 is looking good for us, The highlighting on source cut our  
> > > > indexes sizes in half, thanks!!!
> 
> > > > One thing I noticed is that one of our custom script fields broke with  
> > > > this error:  
> > > > Error: statically-typed variable already defined in scope: value
> 
> > > > The script was basically:  
> > > > String value = \_source[fieldName];  
> > > > // Return first x number of chars from the field
> 
> > > > I guess the value variable is now defined by ES within the scripts  
> > > > execution context? Seems like an unlucky collision. My advice is for  
> > > > ES to prefix all the internal variables in that scope with something  
> > > > like esInternal.
> 
> > > > The update to my script to fix is trivial and similar in the future  
> > > > can be avoided by using my own prefixing on my vars.
> 
> > > > Thanks,  
> > > > Paul

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 20, 2011, 4:08pm UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769/6 "2011-01-20T16:08:07Z")

</div>

Can you open an issue for this? Just so I won't loose track...  
On Wednesday, January 19, 2011 at 8:21 PM, Paul wrote:

> Hey Shay,  
> This simple example should reproduce the issue for you on 0.14.2:  
> [Script field failure · GitHub](https://gist.github.com/786580)
> 
> Thanks!
> 
> On Jan 12, 3:25 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Can you recreate the regression with curl? I will check with mvel.
> > 
> > On Thursday, January 13, 2011 at 12:06 AM, Paul wrote:
> > 
> > > Not sure exactly why, but this had to do with me using a variable  
> > > within the context of a script. On 14.2 here this example fails:  
> > > scriptBuilder.append("String test = "test";");  
> > > scriptBuilder.append("return test.length();");
> > 
> > > Don't get why, but I can work directly off the \_source variable, so  
> > > that makes more sense anyways.
> > 
> > > Thanks,  
> > > Paul
> > 
> > > On Jan 12, 2:36 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> > 
> > > > Err... I think my analysis was off base. Still looking into what my  
> > > > problem is. Apologies for the noise.
> > 
> > > > On Jan 12, 2:19 pm, Paul [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> > 
> > > > > Hey,  
> > > > > 0.14.2 is looking good for us, The highlighting on source cut our  
> > > > > indexes sizes in half, thanks!!!
> > 
> > > > > One thing I noticed is that one of our custom script fields broke with  
> > > > > this error:  
> > > > > Error: statically-typed variable already defined in scope: value
> > 
> > > > > The script was basically:  
> > > > > String value = \_source[fieldName];  
> > > > > // Return first x number of chars from the field
> > 
> > > > > I guess the value variable is now defined by ES within the scripts  
> > > > > execution context? Seems like an unlucky collision. My advice is for  
> > > > > ES to prefix all the internal variables in that scope with something  
> > > > > like esInternal.
> > 
> > > > > The update to my script to fix is trivial and similar in the future  
> > > > > can be avoided by using my own prefixing on my vars.
> > 
> > > > > Thanks,  
> > > > > Paul

---

<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, 4:13am UTC](https://discuss.elastic.co/t/interesting-script-field-nuance-on-0-14-2/3769/7 "2017-07-06T04:13:26Z")

</div>

Closed on July 6, 2017, 4:13am UTC


