# How can I avoid losing data when update es's data by three java threads?

**URL:** <https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185>\
**Category:** Elasticsearch\
**Created:** [December 2, 2015, 2:20pm UTC](https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185 "2015-12-02T14:20:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ourRoy](https://avatars.discourse-cdn.com/v4/letter/o/848f3c/32.png) [@ourRoy](https://discuss.elastic.co/u/ourRoy)\
**Post date:** [December 2, 2015, 2:20pm UTC](https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185/1 "2015-12-02T14:20:52Z")

</div>

how can i avoid losing data when update es's data by three java threads?  
for example：  
one message In es

serv\_id name age sex  
10001 roy 24 boy  
while one java thread to update this's age to 25 ,and another thread update name to lily ,  
finally，this message is not changed to  
serv\_id name age sex  
10001 lily 25 boy

but to  
serv\_id name age sex  
10001 roy 25 boy

name should be lily ,but is not,i wish somebody to give me a way to avoid it;

i am a Chinese，it‘s my first time to require some helps in English forum，my English is not ok,but i really need your help,Thank you !

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 2, 2015, 2:27pm UTC](https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185/2 "2015-12-02T14:27:01Z")

</div>

These documents should be helpful to you:

- [https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html)
- [https://www.elastic.co/guide/en/elasticsearch/guide/current/concurrency-solutions.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/concurrency-solutions.html)

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 2, 2015, 2:40pm UTC](https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185/3 "2015-12-02T14:40:26Z")

</div>

In addition to the resources Magnus pointed to, you can also use [scripted updates](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_scripted_updates) to ensure that updates are executed without affecting each other. This moves the modification of documents to the cluster and automatically retries if there are conflicting updates.

---

<div class="post-metadata">

**Author:** ![ourRoy](https://avatars.discourse-cdn.com/v4/letter/o/848f3c/32.png) [@ourRoy](https://discuss.elastic.co/u/ourRoy)\
**Post date:** [December 3, 2015, 1:12am UTC](https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185/4 "2015-12-03T01:12:15Z")

</div>

Thank you,i got it.😄

---

<div class="post-metadata">

**Author:** ![ourRoy](https://avatars.discourse-cdn.com/v4/letter/o/848f3c/32.png) [@ourRoy](https://discuss.elastic.co/u/ourRoy)\
**Post date:** [December 3, 2015, 1:12am UTC](https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185/5 "2015-12-03T01:12:51Z")

</div>

thank you very much!😋

---

<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:34pm UTC](https://discuss.elastic.co/t/how-can-i-avoid-losing-data-when-update-ess-data-by-three-java-threads/36185/6 "2017-07-05T23:34:02Z")

</div>


