# USE JAVA API operation the update method does not work

**URL:** <https://discuss.elastic.co/t/use-java-api-operation-the-update-method-does-not-work/301972>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 8, 2022, 12:29pm UTC](https://discuss.elastic.co/t/use-java-api-operation-the-update-method-does-not-work/301972 "2022-04-08T12:29:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schmidt-cc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/schmidt-cc/32/104164_2.png) [@Schmidt-cc](https://discuss.elastic.co/u/Schmidt-cc)\
**Post date:** [April 8, 2022, 12:29pm UTC](https://discuss.elastic.co/t/use-java-api-operation-the-update-method-does-not-work/301972/1 "2022-04-08T12:29:15Z")

</div>

Hello all  
Recently， my progarm uesd Elasticsearch update method always fail，code just like this

```auto
public <T extends BaseEntity> void updateDoc(T t, String docIndex) throws IOException {
        //update by id
        UpdateRequest updateRequest = new UpdateRequest(docIndex, String.valueOf(t.getId()));
        updateRequest.timeout(TimeValue.timeValueSeconds(3));
        //set the update time
        t.setUpdated(LocalDateTime.now());
        String updateJson = JSON.toJSONString(t);
        updateRequest.doc(updateJson,XContentType.JSON);
        updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
        UpdateResponse update = restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
        try {
            Thread.sleep(2000);
        }catch (Exception e){
            throw new RuntimeException(e.getMessage());
        }
        logger.info("the status:{}:",update.status());
    }

```

it did not has `updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);`  
and try catch at first,so this method always fail,the question is there is an object that has a field of type List about the business object,when i want to update the field into the Elasticsearch,its failed,in Elasticsearch the field always empty,i think the field of type List has lot of data,so i found some solutions,first one is add `updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);`,but its not work,and then the second is used try catch,its working,but 2s my leader disagree,so i want to find some better solutions.

---

<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:** [May 6, 2022, 12:29pm UTC](https://discuss.elastic.co/t/use-java-api-operation-the-update-method-does-not-work/301972/2 "2022-05-06T12:29:56Z")

</div>

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