ES-update

 1     @Autowired
 2     private ElasticsearchTemplate esTemplate;
 3 
 4     @Override
 5     public boolean updateDoc(CustomerDoc doc) {
 6         UpdateRequest updateRequest = new UpdateRequest();
 7         try {
 8             updateRequest.doc(
 9                     XContentFactory.jsonBuilder().startObject()
10                             .field("nickName", doc.getNickName())
11                             .field("updatedTime", doc.getUpdatedTime())
12                             .endObject()
13             );
14         } catch (IOException e) {
15             e.printStackTrace();
16         }
17 
18         UpdateQuery updateQuery = new UpdateQueryBuilder()
19                 .withIndexName(INDEX_NAME)
20                 .withType(ITEM_TYPE)
21                 .withClass(CustomerDoc.class)
22                 .withId(doc.getId().toString())
23                 .withUpdateRequest(updateRequest).build();
24         esTemplate.update(updateQuery)
25         return true;
26     }

 

posted @ 2019-04-03 13:40  Joke科  阅读(1033)  评论(0编辑  收藏  举报