# Scripting nested docs array with javascript plugin

**URL:** <https://discuss.elastic.co/t/scripting-nested-docs-array-with-javascript-plugin/8404>\
**Category:** Elasticsearch\
**Created:** [July 13, 2012, 8:46am UTC](https://discuss.elastic.co/t/scripting-nested-docs-array-with-javascript-plugin/8404 "2012-07-13T08:46:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [July 13, 2012, 8:46am UTC](https://discuss.elastic.co/t/scripting-nested-docs-array-with-javascript-plugin/8404/1 "2012-07-13T08:46:09Z")

</div>

Hey, all. I'm tired of dealing with mvel, and moved to scripting with  
javascript.  
The issue is that I cannot use simple array functions, even like push to  
push an element to the end of array.

Here's an exception that I'm getting when tried to splice element by index  
from the array of nested docs:  
{  
"error" : "ElasticSearchIllegalArgumentException[failed to execute  
script]; nested: EcmaError[TypeError: Cannot call property splice in object  
null. It is not a function, it is "undefined". (Script1.js#1)]; ",  
"status" : 400  
}

ctx.\_source.my\_array.splice(index, 1)

Everything I try returns me 'Cannot call property %method\_name% in object  
null. It is not a function, it is "undefined"', even though I can  
iterate over the array and set values by index, i.e:  
ctx.\_source.my\_array[index] = some\_doc;

Can anybody help me, please?

---

<div class="post-metadata">

**Author:** ![Kai\_Cherry](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@Kai\_Cherry](https://discuss.elastic.co/u/Kai_Cherry)\
**Post date:** [May 13, 2013, 2:43am UTC](https://discuss.elastic.co/t/scripting-nested-docs-array-with-javascript-plugin/8404/2 "2013-05-13T02:43:11Z")

</div>

I am having the exact same issue. Did you ever resolve it?

-K

On Friday, July 13, 2012 1:46:09 AM UTC-7, Rauan Maemirov wrote:

> Hey, all. I'm tired of dealing with mvel, and moved to scripting with  
> javascript.  
> The issue is that I cannot use simple array functions, even like push to  
> push an element to the end of array.
> 
> Here's an exception that I'm getting when tried to splice element by index  
> from the array of nested docs:  
> {  
> "error" : "ElasticSearchIllegalArgumentException[failed to execute  
> script]; nested: EcmaError[TypeError: Cannot call property splice in object  
> null. It is not a function, it is "undefined". (Script1.js#1)]; ",  
> "status" : 400  
> }
> 
> ctx.\_source.my\_array.splice(index, 1)
> 
> Everything I try returns me 'Cannot call property %method\_name% in object  
> null. It is not a function, it is "undefined"', even though I can  
> iterate over the array and set values by index, i.e:  
> ctx.\_source.my\_array[index] = some\_doc;
> 
> Can anybody help me, please?

--  
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:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [May 13, 2013, 6:03am UTC](https://discuss.elastic.co/t/scripting-nested-docs-array-with-javascript-plugin/8404/3 "2013-05-13T06:03:57Z")

</div>

Hi, Kai. Yeah, I ended up iterating and adding value by index.

2013/5/13 Kai Cherry [rnsksoft@gmail.com](mailto:rnsksoft@gmail.com)

> I am having the exact same issue. Did you ever resolve it?
> 
> -K
> 
> On Friday, July 13, 2012 1:46:09 AM UTC-7, Rauan Maemirov wrote:
> 
> > Hey, all. I'm tired of dealing with mvel, and moved to scripting with  
> > javascript.  
> > The issue is that I cannot use simple array functions, even like push to  
> > push an element to the end of array.
> > 
> > Here's an exception that I'm getting when tried to splice element by  
> > index from the array of nested docs:  
> > {  
> > "error" : " **ElasticSearchIllegalArgumentEx** ception[failed to execute  
> > script]; nested: EcmaError[TypeError: Cannot call property splice in object  
> > null. It is not a function, it is "undefined". (Script1.js#1)]; ",  
> > "status" : 400  
> > }
> > 
> > ctx.\_source.my\_array.splice(\*\*index, 1)
> > 
> > Everything I try returns me 'Cannot call property %method\_name% in object  
> > null. It is not a function, it is "undefined"', even though I can  
> > iterate over the array and set values by index, i.e:  
> > ctx.\_source.my\_array[index] = some\_doc;
> > 
> > Can anybody help me, please?
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/7ekxjyUjtH8/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/7ekxjyUjtH8/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, 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:37am UTC](https://discuss.elastic.co/t/scripting-nested-docs-array-with-javascript-plugin/8404/4 "2017-07-06T02:37:00Z")

</div>


