# Update existing values within a list or array in Elastic Search

**URL:** https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279
**Category:** Elasticsearch
**Created:** [June 24, 2014, 7:18am UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279 "2014-06-24T07:18:17Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Madhumita\_Sadhukhan](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@Madhumita\_Sadhukhan](https://discuss.elastic.co/u/Madhumita_Sadhukhan)
#### Post date: [June 24, 2014, 7:18am UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/1 "2014-06-24T07:18:17Z")

</div>

I have a requirement where I need to update(not append) existing values  
within a list or array in Elastic Search.  
Is this feature supported in elastic search?

For eg:

I have a field called jobs as part of my document

"jobs": [  
{  
"status": "InProgress",  
"runId": 1,  
"start\_date": 2101112,  
"orderId": "undefined"  
},  
{  
"status": "InProgress",  
"runId": 2,  
"start\_date": 2101112,  
"orderId": "undefined"  
},  
],  
and I am required to update the orderId for each job run to different  
values.  
Currently I am only able to append a job but I cannot update the attributes  
of each job later.  
Is this usecase supported and possible in Elastic Search?

--  
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/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 24, 2014, 7:27am UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/2 "2014-06-24T07:27:05Z")

</div>

If you send the full document without the element you need to remove in the array, this should work fine.  
How do you actually update your document?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan ([madhumita.sadhukhan@gmail.com](mailto:madhumita.sadhukhan@gmail.com)) a écrit:

I have a requirement where I need to update(not append) existing values within a list or array in Elastic Search.  
Is this feature supported in elastic search?

For eg:

I have a field called jobs as part of my document

## "jobs": [{ "status": "InProgress", "runId": 1, "start\_date": 2101112, "orderId": "undefined" }, { "status": "InProgress", "runId": 2, "start\_date": 2101112, "orderId": "undefined" },], and I am required to update the orderId for each job run to different values. Currently I am only able to append a job but I cannot update the attributes of each job later. Is this usecase supported and possible in Elastic Search?

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/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53a92849.66334873.950f%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53a92849.66334873.950f%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Madhumita\_Sadhukhan](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@Madhumita\_Sadhukhan](https://discuss.elastic.co/u/Madhumita_Sadhukhan)
#### Post date: [June 24, 2014, 10:51am UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/3 "2014-06-24T10:51:50Z")

</div>

I am not removing any element from an array I need to update particular  
existing elements within an array.  
Currently I ma using the Update API in Elastic Search to append new  
elements within the array but it fails when I try to update values of  
existing elements.

For eg:

I am able to add a new record as follows to jobs list using Update API  
scripts

{  
"status": "InProgress",  
"runId": 2,  
"start\_date": 2101112,  
"orderId": "undefined"  
},

What I need is how to update orderId value from 'undefined' to say 'abcd'  
using update api.  
Is this supported?  
Is Elastic Search supporting indexing in arrays or lists?

On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:

> If you send the full document without the element you need to remove in  
> the array, this should work fine.  
> How do you actually update your document?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com)  
> \<javascript:\>) a écrit:
> 
> I have a requirement where I need to update(not append) existing values  
> within a list or array in Elastic Search.  
> Is this feature supported in Elasticsearch?
> 
> For eg:
> 
> I have a field called jobs as part of my document
> 
> ## "jobs": [{ "status": "InProgress", "runId": 1, "start\_date": 2101112, "orderId": "undefined" }, { "status": "InProgress", "runId": 2, "start\_date": 2101112, "orderId": "undefined" },], and I am required to update the orderId for each job run to different values. Currently I am only able to append a job but I cannot update the attributes of each job later. Is this usecase supported and possible in Elastic Search?
> 
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 24, 2014, 11:02am UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/4 "2014-06-24T11:02:03Z")

</div>

Just send the full new version of your document and you're done.  
Elasticsearch will index the new content.

If I did not answer to you question, may be you should provide an example as a Gist so we can comment with more details???

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan ([madhumita.sadhukhan@gmail.com](mailto:madhumita.sadhukhan@gmail.com)) a écrit:

I am not removing any element from an array I need to update particular existing elements within an array.  
Currently I ma using the Update API in Elastic Search to append new elements within the array but it fails when I try to update values of existing elements.

For eg:

I am able to add a new record as follows to jobs list using Update API scripts

{  
"status": "InProgress",  
"runId": 2,  
"start\_date": 2101112,  
"orderId": "undefined"  
},

What I need is how to update orderId value from 'undefined' to say 'abcd' using update api.  
Is this supported?  
Is Elastic Search supporting indexing in arrays or lists?

On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:  
If you send the full document without the element you need to remove in the array, this should work fine.  
How do you actually update your document?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com)) a écrit:

I have a requirement where I need to update(not append) existing values within a list or array in Elastic Search.  
Is this feature supported in elastic search?

For eg:

I have a field called jobs as part of my document

## "jobs": [{ "status": "InProgress", "runId": 1, "start\_date": 2101112, "orderId": "undefined" }, { "status": "InProgress", "runId": 2, "start\_date": 2101112, "orderId": "undefined" },], and I am required to update the orderId for each job run to different values. Currently I am only able to append a job but I cannot update the attributes of each job later. Is this usecase supported and possible in Elastic Search?

## 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com). To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com). For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

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/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53a95aab.3352255a.950f%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53a95aab.3352255a.950f%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Rajit\_Garg](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@Rajit\_Garg](https://discuss.elastic.co/u/Rajit_Garg)
#### Post date: [October 7, 2014, 1:08pm UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/5 "2014-10-07T13:08:38Z")

</div>

I also have the same question, I have a array type field in my document of  
Elasticsearch, like below:-

"prog\_lists": [  
{  
"description": "engineer",  
"age": 25,  
"name": "ashu"  
},  
{  
"description": "programmer",  
"age": 26,  
"name": "rajit"  
},  
{  
"description": "designer",  
"age": 27,  
"name": "naveen"  
}]

I want to update only one object from this array i.e. i want to query where  
name equals to ashu then update his age to 30. How I can achieve this in  
Elasticsearch

please suggest something...

On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:

> Just send the full new version of your document and you're done.  
> Elasticsearch will index the new content.
> 
> If I did not answer to you question, may be you should provide an example  
> as a Gist so we can comment with more details???
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com)  
> \<javascript:\>) a écrit:
> 
> I am not removing any element from an array I need to update particular  
> existing elements within an array.  
> Currently I ma using the Update API in Elastic Search to append new  
> elements within the array but it fails when I try to update values of  
> existing elements.
> 
> For eg:
> 
> I am able to add a new record as follows to jobs list using Update API  
> scripts
> 
> {  
> "status": "InProgress",  
> "runId": 2,  
> "start\_date": 2101112,  
> "orderId": "undefined"  
> },
> 
> What I need is how to update orderId value from 'undefined' to say 'abcd'  
> using update api.  
> Is this supported?  
> Is Elastic Search supporting indexing in arrays or lists?
> 
> On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:
> 
> > If you send the full document without the element you need to remove in  
> > the array, this should work fine.  
> > How do you actually update your document?
> > 
> > ```
> > -- 
> > 
> > ```
> > 
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com))  
> > a écrit:
> > 
> > I have a requirement where I need to update(not append) existing values  
> > within a list or array in Elastic Search.  
> > Is this feature supported in Elasticsearch?
> > 
> > For eg:
> > 
> > I have a field called jobs as part of my document
> > 
> > ## "jobs": [{ "status": "InProgress", "runId": 1, "start\_date": 2101112, "orderId": "undefined" }, { "status": "InProgress", "runId": 2, "start\_date": 2101112, "orderId": "undefined" },], and I am required to update the orderId for each job run to different values. Currently I am only able to append a job but I cannot update the attributes of each job later. Is this usecase supported and possible in Elastic Search?
> > 
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/4d5ea21f-dbb7-4fd0-9649-8e0131357738%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4d5ea21f-dbb7-4fd0-9649-8e0131357738%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Rajit\_Garg](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@Rajit\_Garg](https://discuss.elastic.co/u/Rajit_Garg)
#### Post date: [October 8, 2014, 11:11am UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/6 "2014-10-08T11:11:43Z")

</div>

Hey

I figured it out, I am able to update but I am not able to remove object  
that satisfies the condition

PUT twitter/twit/1  
{  
"list": [  
{  
"tweet\_id": "1",  
"a": "b"  
},  
{  
"tweet\_id": "123",  
"a": "f"  
}  
]  
}

POST /twitter/twit/1/\_update  
{  
"script": "foreach (item : ctx.\_source.list) {if (item['tweet\_id'] ==  
tweet\_id) { item['new\_field'] = 'ghi'; } }",  
"params": {  
"tweet\_id": "123"  
}  
}  
this is working

for remove i am doing this

POST /twitter/twit/1/\_update  
{  
"script": "foreach (item : ctx.\_source.list) {if (item['tweet\_id'] ==  
tweet\_id) {ctx.\_source.list.remove(item); } }",  
"params": {  
"tweet\_id": "123"  
}  
}

but this is not working and giving this error,

ElasticsearchIllegalArgumentException[failed to execute script]; nested:  
ConcurrentModificationException;  
Error: ElasticsearchIllegalArgumentException[failed to execute script];  
nested: ConcurrentModificationException;  
..................................  
...............................

please help........

On Tuesday, October 7, 2014 6:38:38 PM UTC+5:30, Rajit Garg wrote:

> I also have the same question, I have a array type field in my document  
> of Elasticsearch, like below:-
> 
> "prog\_lists": [  
> {  
> "description": "engineer",  
> "age": 25,  
> "name": "ashu"  
> },  
> {  
> "description": "programmer",  
> "age": 26,  
> "name": "rajit"  
> },  
> {  
> "description": "designer",  
> "age": 27,  
> "name": "naveen"  
> }]
> 
> I want to update only one object from this array i.e. i want to query  
> where name equals to ashu then update his age to 30. How I can achieve  
> this in Elasticsearch
> 
> please suggest something...
> 
> On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:
> 
> > Just send the full new version of your document and you're done.  
> > Elasticsearch will index the new content.
> > 
> > If I did not answer to you question, may be you should provide an example  
> > as a Gist so we can comment with more details???
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com))  
> > a écrit:
> > 
> > I am not removing any element from an array I need to update particular  
> > existing elements within an array.  
> > Currently I ma using the Update API in Elastic Search to append new  
> > elements within the array but it fails when I try to update values of  
> > existing elements.
> > 
> > For eg:
> > 
> > I am able to add a new record as follows to jobs list using Update API  
> > scripts
> > 
> > {  
> > "status": "InProgress",  
> > "runId": 2,  
> > "start\_date": 2101112,  
> > "orderId": "undefined"  
> > },
> > 
> > What I need is how to update orderId value from 'undefined' to say 'abcd'  
> > using update api.  
> > Is this supported?  
> > Is Elastic Search supporting indexing in arrays or lists?
> > 
> > On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:
> > 
> > > If you send the full document without the element you need to remove  
> > > in the array, this should work fine.  
> > > How do you actually update your document?
> > > 
> > > ```
> > > -- 
> > > 
> > > ```
> > > 
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > 
> > > Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com))  
> > > a écrit:
> > > 
> > > I have a requirement where I need to update(not append) existing  
> > > values within a list or array in Elastic Search.  
> > > Is this feature supported in Elasticsearch?
> > > 
> > > For eg:
> > > 
> > > I have a field called jobs as part of my document
> > > 
> > > ## "jobs": [{ "status": "InProgress", "runId": 1, "start\_date": 2101112, "orderId": "undefined" }, { "status": "InProgress", "runId": 2, "start\_date": 2101112, "orderId": "undefined" },], and I am required to update the orderId for each job run to different values. Currently I am only able to append a job but I cannot update the attributes of each job later. Is this usecase supported and possible in Elastic Search?
> > > 
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/3fc06c06-656d-4fe9-94d9-07f3d8f6f9e7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3fc06c06-656d-4fe9-94d9-07f3d8f6f9e7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Rajit\_Garg](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@Rajit\_Garg](https://discuss.elastic.co/u/Rajit_Garg)
#### Post date: [October 10, 2014, 1:26pm UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/7 "2014-10-10T13:26:44Z")

</div>

**I have got my answer, and its solution is**

```
POST /twitter/twit/1/_update

{
  "script": "item_to_remove = nil; foreach (item : ctx._source.list) { 

```

if (item['tweet\_id'] == tweet\_id) { item\_to\_remove=item; } } if  
(item\_to\_remove != nil) ctx.\_source.list.remove(item\_to\_remove);",  
"params": {"tweet\_id": "123"}  
}

**if you have more than one item that matches the criteria, use a list  
instead:**

```
POST /twitter/twit/1/_update
{
  "script": "items_to_remove = []; foreach (item : ctx._source.list) { 

```

if (item['tweet\_id'] == tweet\_id) { items\_to\_remove.add(item); } } foreach  
(item : items\_to\_remove) {ctx.\_source.list.remove(item);}",  
"params": {"tweet\_id": "123"}  
}

On Tuesday, June 24, 2014 12:48:17 PM UTC+5:30, Madhumita Sadhukhan wrote:

> I have a requirement where I need to update(not append) existing values  
> within a list or array in Elastic Search.  
> Is this feature supported in Elasticsearch?
> 
> For eg:
> 
> I have a field called jobs as part of my document
> 
> "jobs": [  
> {  
> "status": "InProgress",  
> "runId": 1,  
> "start\_date": 2101112,  
> "orderId": "undefined"  
> },  
> {  
> "status": "InProgress",  
> "runId": 2,  
> "start\_date": 2101112,  
> "orderId": "undefined"  
> },  
> ],  
> and I am required to update the orderId for each job run to different  
> values.  
> Currently I am only able to append a job but I cannot update the  
> attributes of each job later.  
> Is this usecase supported and possible in Elastic Search?

On Wednesday, October 8, 2014 4:41:45 PM UTC+5:30, Rajit Garg wrote:

> Hey
> 
> I figured it out, I am able to update but I am not able to remove object  
> that satisfies the condition
> 
> PUT twitter/twit/1  
> {  
> "list": [  
> {  
> "tweet\_id": "1",  
> "a": "b"  
> },  
> {  
> "tweet\_id": "123",  
> "a": "f"  
> }  
> ]  
> }
> 
> POST /twitter/twit/1/\_update  
> {  
> "script": "foreach (item : ctx.\_source.list) {if (item['tweet\_id'] ==  
> tweet\_id) { item['new\_field'] = 'ghi'; } }",  
> "params": {  
> "tweet\_id": "123"  
> }  
> }  
> this is working
> 
> for remove i am doing this
> 
> POST /twitter/twit/1/\_update  
> {  
> "script": "foreach (item : ctx.\_source.list) {if (item['tweet\_id'] ==  
> tweet\_id) {ctx.\_source.list.remove(item); } }",  
> "params": {  
> "tweet\_id": "123"  
> }  
> }
> 
> but this is not working and giving this error,
> 
> ElasticsearchIllegalArgumentException[failed to execute script]; nested:  
> ConcurrentModificationException;  
> Error: ElasticsearchIllegalArgumentException[failed to execute script];  
> nested: ConcurrentModificationException;  
> ..................................  
> ...............................
> 
> please help........
> 
> On Tuesday, October 7, 2014 6:38:38 PM UTC+5:30, Rajit Garg wrote:
> 
> > I also have the same question, I have a array type field in my document  
> > of Elasticsearch, like below:-
> > 
> > "prog\_lists": [  
> > {  
> > "description": "engineer",  
> > "age": 25,  
> > "name": "ashu"  
> > },  
> > {  
> > "description": "programmer",  
> > "age": 26,  
> > "name": "rajit"  
> > },  
> > {  
> > "description": "designer",  
> > "age": 27,  
> > "name": "naveen"  
> > }]
> > 
> > I want to update only one object from this array i.e. i want to query  
> > where name equals to ashu then update his age to 30. How I can achieve  
> > this in Elasticsearch
> > 
> > please suggest something...
> > 
> > On Tuesday, June 24, 2014 4:32:20 PM UTC+5:30, David Pilato wrote:
> > 
> > > Just send the full new version of your document and you're done.  
> > > Elasticsearch will index the new content.
> > > 
> > > If I did not answer to you question, may be you should provide an  
> > > example as a Gist so we can comment with more details???
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > 
> > > Le 24 juin 2014 à 12:51:54, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com))  
> > > a écrit:
> > > 
> > > I am not removing any element from an array I need to update particular  
> > > existing elements within an array.  
> > > Currently I ma using the Update API in Elastic Search to append new  
> > > elements within the array but it fails when I try to update values of  
> > > existing elements.
> > > 
> > > For eg:
> > > 
> > > I am able to add a new record as follows to jobs list using Update API  
> > > scripts
> > > 
> > > {  
> > > "status": "InProgress",  
> > > "runId": 2,  
> > > "start\_date": 2101112,  
> > > "orderId": "undefined"  
> > > },
> > > 
> > > What I need is how to update orderId value from 'undefined' to say  
> > > 'abcd' using update api.  
> > > Is this supported?  
> > > Is Elastic Search supporting indexing in arrays or lists?
> > > 
> > > On Tuesday, June 24, 2014 12:57:15 PM UTC+5:30, David Pilato wrote:
> > > 
> > > > If you send the full document without the element you need to remove  
> > > > in the array, this should work fine.  
> > > > How do you actually update your document?
> > > > 
> > > > ```
> > > > -- 
> > > > 
> > > > ```
> > > > 
> > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > 
> > > > Le 24 juin 2014 à 09:18:20, Madhumita Sadhukhan ([madhumita...@gmail.com](mailto:madhumita...@gmail.com))  
> > > > a écrit:
> > > > 
> > > > I have a requirement where I need to update(not append) existing  
> > > > values within a list or array in Elastic Search.  
> > > > Is this feature supported in Elasticsearch?
> > > > 
> > > > For eg:
> > > > 
> > > > I have a field called jobs as part of my document
> > > > 
> > > > ## "jobs": [{ "status": "InProgress", "runId": 1, "start\_date": 2101112, "orderId": "undefined" }, { "status": "InProgress", "runId": 2, "start\_date": 2101112, "orderId": "undefined" },], and I am required to update the orderId for each job run to different values. Currently I am only able to append a job but I cannot update the attributes of each job later. Is this usecase supported and possible in Elastic Search?
> > > > 
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ba7f8f47-3578-4b47-9410-9dd2622911a2%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2e69ec6b-4c53-4802-ab0a-49aa4f395c97%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/df051e8d-26a6-4e96-a021-27dc74d8d091%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df051e8d-26a6-4e96-a021-27dc74d8d091%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, 12:57am UTC](https://discuss.elastic.co/t/update-existing-values-within-a-list-or-array-in-elastic-search/18279/8 "2017-07-06T00:57:04Z")

</div>


