# Efficiently updating a large number of array-type fields

**URL:** <https://discuss.elastic.co/t/efficiently-updating-a-large-number-of-array-type-fields/35485>\
**Category:** Elasticsearch\
**Created:** [November 24, 2015, 8:53pm UTC](https://discuss.elastic.co/t/efficiently-updating-a-large-number-of-array-type-fields/35485 "2015-11-24T20:53:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![beowulfenator](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beowulfenator/32/4905_2.png) [@beowulfenator](https://discuss.elastic.co/u/beowulfenator)\
**Post date:** [November 24, 2015, 8:53pm UTC](https://discuss.elastic.co/t/efficiently-updating-a-large-number-of-array-type-fields/35485/1 "2015-11-24T20:53:49Z")

</div>

I am looking for an efficient way to update large numbers of entries  
in my index. Let's say my ElasticSearch index contains documents with  
tags. Tags are expressed as arrays of strings. So one document might  
have tags ['foo', 'bar'] and some other document might have tags ['bar', 'baz'].

Typically I need to add a certain tag to a number of documents (I  
know their IDs) and remove this tag from all other documents. There are  
about half a million documents in the index and growing, and I need to  
update tens, maybe hundreds of thousands of documents.

The operation doesn't need to be atomic. There are no problems with  
concurrent writing, I can be pretty sure there are no other write  
operations on that index while I'm updating.

My goal is for this update to be done as quickly as possible.

Let's imagine I need to set tag 'foo' to documents 123, 456 and 555.

Should I remove tag 'foo' from all documents in the  
index, and then add it to 123, 456 and 555? Or should I first get the  
list of documents that need to have that tag removed, then remove tag  
only from those documents and add only to documents that need it?

Are there any other ways of solving this problem?

---

<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 5, 2017, 11:36pm UTC](https://discuss.elastic.co/t/efficiently-updating-a-large-number-of-array-type-fields/35485/2 "2017-07-05T23:36:11Z")

</div>


