# Most efficient way to bulk update index?

**URL:** <https://discuss.elastic.co/t/most-efficient-way-to-bulk-update-index/131480>\
**Category:** Elasticsearch\
**Created:** [May 11, 2018, 1:32pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-bulk-update-index/131480 "2018-05-11T13:32:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [May 11, 2018, 1:32pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-bulk-update-index/131480/1 "2018-05-11T13:32:05Z")

</div>

Hi,

Here is my requirement.  
This is what I need to do ...  
`if (indexedField1.value contains pattern1) indexedField1.value = newValue; add a new indexedField2`  
I do realize there is a programmatic way of doing this in Java for example:  
1. Fetch only indexedField1 using \_source filtering  
2. Check the value  
3. Create \_bulk update and create statements  
4. Execute the \_bulk call

I wanted to verify if the above would work.  
More importantly, is there a better way to do this, for example, entire within elastic search, hence more efficient?

Thanks!

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [May 14, 2018, 6:24pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-bulk-update-index/131480/2 "2018-05-14T18:24:53Z")

</div>

Any thoughts on this will be very helpful.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [May 17, 2018, 4:50am UTC](https://discuss.elastic.co/t/most-efficient-way-to-bulk-update-index/131480/3 "2018-05-17T04:50:10Z")

</div>

Using `_source` filtering does not makes it fast. Actually, it adds overhead since Elasticsearch needs to parse the `_source`, apply the filtering logic and serialize a new document.

The most efficient way of doing what you are describing is by either using the [Reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) with a script or using the [Update By Query API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) also with a script.

Both of which could be leveraged if you can translate `indexedField1.value contains pattern1` into a query.

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [May 17, 2018, 12:33pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-bulk-update-index/131480/4 "2018-05-17T12:33:05Z")

</div>

Thank you, very useful.  
Yea I figured anything that can be natively done within ES would be preferred. I just wasnt sure of it. More importantly Im not too familiar with the concept of scripts.  
I guess here is my opportunity to explore, learn and apply it.

Once again, appreciate your response.

---

<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:** [June 14, 2018, 12:33pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-bulk-update-index/131480/5 "2018-06-14T12:33:17Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
