# How to convert update method to insert-array method (Java)

**URL:** https://discuss.elastic.co/t/how-to-convert-update-method-to-insert-array-method-java/104949
**Category:** Elasticsearch
**Created:** [October 23, 2017, 6:06pm UTC](https://discuss.elastic.co/t/how-to-convert-update-method-to-insert-array-method-java/104949 "2017-10-23T18:06:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![arturcortereal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arturcortereal/32/23299_2.png) [@arturcortereal](https://discuss.elastic.co/u/arturcortereal)
#### Post date: [October 23, 2017, 6:06pm UTC](https://discuss.elastic.co/t/how-to-convert-update-method-to-insert-array-method-java/104949/1 "2017-10-23T18:06:38Z")

</div>

Hello guys.

Looks like I'm having some issues while updating an array. I think that my code is suffering from delay after the update. This is my code. I'm running it several times. If I put a sleep after the update, it will work. But it is not a good practice and it does not fit on my project.

```
             listOne.add(peanut); // The listOne is a Set<String>

	UpdateRequest updateRequest = new UpdateRequest();
	updateRequest.index(aux.getIndex());
	updateRequest.type(org.core.database.json.Element.classType);
	updateRequest.id(elementId.toString());
	updateRequest.doc("listOne",listOne); // The new doc
	element.setListOne(listOne); // Sets the new list for future updates
	
	// Retry 3 times before failing the update
	updateRequest.retryOnConflict(3);
	client.update(updateRequest).get(); // Updates it

```

Imagine that i want to add 10 different peanuts. I cannot do it, because with this method, ES will lose data. So I want a method that allows me to store all the data without losing one (or more) of the peanuts. (append the new peanut to the array without visiting the data stored in ES could be a good solution, but I don't know how to implement it).

The version of the ES is 2.3.4.

Thank you guys.

---

<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: [November 20, 2017, 6:06pm UTC](https://discuss.elastic.co/t/how-to-convert-update-method-to-insert-array-method-java/104949/2 "2017-11-20T18:06:41Z")

</div>

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