# Update an Elasticsearch document's array field without using scripting

**URL:** https://discuss.elastic.co/t/update-an-elasticsearch-documents-array-field-without-using-scripting/21721
**Category:** Elasticsearch
**Created:** [January 19, 2015, 9:29pm UTC](https://discuss.elastic.co/t/update-an-elasticsearch-documents-array-field-without-using-scripting/21721 "2015-01-19T21:29:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jason\_Lee](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@Jason\_Lee](https://discuss.elastic.co/u/Jason_Lee)
#### Post date: [January 19, 2015, 9:29pm UTC](https://discuss.elastic.co/t/update-an-elasticsearch-documents-array-field-without-using-scripting/21721/1 "2015-01-19T21:29:35Z")

</div>

I'm trying to add new values to an existing array field in a document. I've  
noticed that using the update api just overwrites the entire array field.  
So far all the examples I have found are using scripting but I can't do  
that because of security. Adding the script in the config/script folder as  
per [http://www.elasticsearch.org/blog/scripting-security/](http://www.elasticsearch.org/blog/scripting-security/) is not ideal  
because that would mean I would be required to manually place the script in  
wherever our ES instances would be installed, which could be alot of  
places.

I'm actually using the Apache HttpClient to make http calls for GET and  
POST etc., and a way around this is to make multiple requests in order to  
get the existing array, update it from Java code, and then send a request  
with the updated array. However I do not like this approach as I end up  
making more than one request. I do not want to use the Java API for this  
(even if there is a way).

Is there some other way to do this?

--  
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/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Jason\_Lee](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@Jason\_Lee](https://discuss.elastic.co/u/Jason_Lee)
#### Post date: [January 21, 2015, 8:59pm UTC](https://discuss.elastic.co/t/update-an-elasticsearch-documents-array-field-without-using-scripting/21721/2 "2015-01-21T20:59:40Z")

</div>

Just another note. A sequence of GET and POST can cause concurrency issues  
if more than one of our application nodes are communicating with the ES  
instance, if they try update at the same/similar time, so this is really  
not ideal.

--  
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/ae21ee86-0af5-4ed7-9898-351834edc91c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ae21ee86-0af5-4ed7-9898-351834edc91c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [January 21, 2015, 9:50pm UTC](https://discuss.elastic.co/t/update-an-elasticsearch-documents-array-field-without-using-scripting/21721/3 "2015-01-21T21:50:20Z")

</div>

The current default scripting language, groovy, is sandboxed. If you still  
don't want to use it your only option is the get update put sequence.  
On Jan 19, 2015 1:29 PM, "Jason Lee" [pump.mini90@gmail.com](mailto:pump.mini90@gmail.com) wrote:

> I'm trying to add new values to an existing array field in a document.  
> I've noticed that using the update api just overwrites the entire array  
> field. So far all the examples I have found are using scripting but I can't  
> do that because of security. Adding the script in the config/script folder  
> as per [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/scripting-security/) is not ideal  
> because that would mean I would be required to manually place the script in  
> wherever our ES instances would be installed, which could be alot of  
> places.
> 
> I'm actually using the Apache HttpClient to make http calls for GET and  
> POST etc., and a way around this is to make multiple requests in order to  
> get the existing array, update it from Java code, and then send a request  
> with the updated array. However I do not like this approach as I end up  
> making more than one request. I do not want to use the Java API for this  
> (even if there is a way).
> 
> Is there some other way to do this?
> 
> --  
> 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/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%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/CAPmjWd22B7%2B0%2B8mcMQCqtnWcfxZ1uxp6jzLDAiEa83EkFO\_dJg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd22B7%2B0%2B8mcMQCqtnWcfxZ1uxp6jzLDAiEa83EkFO_dJg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Jason\_Lee](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@Jason\_Lee](https://discuss.elastic.co/u/Jason_Lee)
#### Post date: [January 22, 2015, 1:47am UTC](https://discuss.elastic.co/t/update-an-elasticsearch-documents-array-field-without-using-scripting/21721/4 "2015-01-22T01:47:11Z")

</div>

Ah ok, so I don't have to worry about any security risks then if I just use  
the defaults?

On Thursday, January 22, 2015 at 10:50:32 AM UTC+13, Nikolas Everett wrote:

> The current default scripting language, groovy, is sandboxed. If you still  
> don't want to use it your only option is the get update put sequence.  
> On Jan 19, 2015 1:29 PM, "Jason Lee" \<[pump....@gmail.com](mailto:pump....@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > I'm trying to add new values to an existing array field in a document.  
> > I've noticed that using the update api just overwrites the entire array  
> > field. So far all the examples I have found are using scripting but I can't  
> > do that because of security. Adding the script in the config/script folder  
> > as per [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/scripting-security/) is not  
> > ideal because that would mean I would be required to manually place the  
> > script in wherever our ES instances would be installed, which could be alot  
> > of places.
> > 
> > I'm actually using the Apache HttpClient to make http calls for GET and  
> > POST etc., and a way around this is to make multiple requests in order to  
> > get the existing array, update it from Java code, and then send a request  
> > with the updated array. However I do not like this approach as I end up  
> > making more than one request. I do not want to use the Java API for this  
> > (even if there is a way).
> > 
> > Is there some other way to do this?
> > 
> > --  
> > 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/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/e7f5a2ad-2e0b-4686-b90d-e0d5c6fb720c%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/4cbdb372-a04c-4216-be98-db090d8aeddb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4cbdb372-a04c-4216-be98-db090d8aeddb%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:37am UTC](https://discuss.elastic.co/t/update-an-elasticsearch-documents-array-field-without-using-scripting/21721/5 "2017-07-06T00:37:25Z")

</div>


