# Update object array

**URL:** <https://discuss.elastic.co/t/update-object-array/17614>\
**Category:** Elasticsearch\
**Created:** [May 20, 2014, 7:39am UTC](https://discuss.elastic.co/t/update-object-array/17614 "2014-05-20T07:39:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmx](https://avatars.discourse-cdn.com/v4/letter/k/d07c76/32.png) [@kmx](https://discuss.elastic.co/u/kmx)\
**Post date:** [May 20, 2014, 7:39am UTC](https://discuss.elastic.co/t/update-object-array/17614/1 "2014-05-20T07:39:59Z")

</div>

Hi,  
Im trying to update an item from this array :

myarray : [  
{  
id: 1,  
valid: false  
},  
{  
id: 23,  
valid: false  
},  
{  
id: 456,  
valid: false  
}  
]

I would like to set 'valid' to 'true' for item with 'id' : 23

I tried using the 'script' query without success

How can i achieve that ?

--  
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/e96f11d3-75e0-4472-8f3f-b6a500aad712%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e96f11d3-75e0-4472-8f3f-b6a500aad712%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![kmx](https://avatars.discourse-cdn.com/v4/letter/k/d07c76/32.png) [@kmx](https://discuss.elastic.co/u/kmx)\
**Post date:** [May 20, 2014, 11:26am UTC](https://discuss.elastic.co/t/update-object-array/17614/2 "2014-05-20T11:26:50Z")

</div>

i found a way to do it after checking MVEL syntax:  
...  
script: "  
foreach(item : ctx.\_source.myarray) {  
if(item.id == 23) {  
item.valid = true;  
}  
}  
"  
...

Can someone tell me if this is the proper way to do it ?

Le mardi 20 mai 2014 09:39:59 UTC+2, kmx a écrit :

> Hi,  
> Im trying to update an item from this array :
> 
> myarray : [  
> {  
> id: 1,  
> valid: false  
> },  
> {  
> id: 23,  
> valid: false  
> },  
> {  
> id: 456,  
> valid: false  
> }  
> ]
> 
> I would like to set 'valid' to 'true' for item with 'id' : 23
> 
> I tried using the 'script' query without success
> 
> How can i achieve that ?

--  
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/9c7f6c5e-dd7c-47a4-b32c-92e20ffd31c8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9c7f6c5e-dd7c-47a4-b32c-92e20ffd31c8%40googlegroups.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:28am UTC](https://discuss.elastic.co/t/update-object-array/17614/3 "2017-07-06T01:28:10Z")

</div>


