USE JAVA API operation the update method does not work

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

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.

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