# Updating an existing object in nested type

**URL:** https://discuss.elastic.co/t/updating-an-existing-object-in-nested-type/16865
**Category:** Elasticsearch
**Created:** [April 8, 2014, 5:45am UTC](https://discuss.elastic.co/t/updating-an-existing-object-in-nested-type/16865 "2014-04-08T05:45:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kalyan\_Srinivas](https://avatars.discourse-cdn.com/v4/letter/k/779978/32.png) [@Kalyan\_Srinivas](https://discuss.elastic.co/u/Kalyan_Srinivas)
#### Post date: [April 8, 2014, 5:45am UTC](https://discuss.elastic.co/t/updating-an-existing-object-in-nested-type/16865/1 "2014-04-08T05:45:22Z")

</div>

Hi all  
can somebody help me/guide me on how to update an existing nested type,i  
could get to add new object to the nested array of objects but not update  
an existing nested type  
example document from ES  
{  
code:1234  
blogname:my first blog  
association:[{  
code:234,  
imagepath:"/web/z/l/test.jpg" },  
code :546  
imagepath:"Null"  
]  
so my question is how would i update my object with "code:546" path from  
NULL to "/web/l/z/sample.jpg"

my update command looks like  
{ "update" : { "\_index" : "blog", "\_type" : "posts", "\_id" : "4611" } }  
{ "script" : "WHAT CONDITION SHOULD GO HERE ", "params" : { "association":  
[{"code": 546, "path": "/web/l/z/sample.jpg" }]}}  
How to get an existing object from array and update it..

Thanks  
Kalyan

--  
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/7135f190-b52a-4db4-9c03-3a5c7d5d3b5b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7135f190-b52a-4db4-9c03-3a5c7d5d3b5b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [April 9, 2014, 6:23pm UTC](https://discuss.elastic.co/t/updating-an-existing-object-in-nested-type/16865/2 "2014-04-09T18:23:57Z")

</div>

Th script could iterate and do something like this for example:

{  
"script": "for ($a: ctx.\_source.association) { if ($a.code == 546)  
$a.imagepath='zzz'; }"  
}

--  
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/fa3e31ae-f5c0-42e3-b050-de5192e11add%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa3e31ae-f5c0-42e3-b050-de5192e11add%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Kalyan\_Srinivas](https://avatars.discourse-cdn.com/v4/letter/k/779978/32.png) [@Kalyan\_Srinivas](https://discuss.elastic.co/u/Kalyan_Srinivas)
#### Post date: [April 10, 2014, 1:51am UTC](https://discuss.elastic.co/t/updating-an-existing-object-in-nested-type/16865/3 "2014-04-10T01:51:53Z")

</div>

Thank you so very much,this answer solved a lot of problems,YAY..!! Binh

On Wednesday, April 9, 2014 11:23:57 AM UTC-7, Binh Ly wrote:

> Th script could iterate and do something like this for example:
> 
> {  
> "script": "for ($a: ctx.\_source.association) { if ($a.code == 546)  
> $a.imagepath='zzz'; }"  
> }

--  
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/7307cae1-c96b-4f65-8433-26dd885d496b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7307cae1-c96b-4f65-8433-26dd885d496b%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:36am UTC](https://discuss.elastic.co/t/updating-an-existing-object-in-nested-type/16865/4 "2017-07-06T01:36:59Z")

</div>


