Skip to content

Commit b72c8a5

Browse files
authored
Update ElasticSearchRestAPI.java
1 parent 8fcfd0c commit b72c8a5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

springboot-elasticsearch/src/main/java/com/example/elasticsearch/api/ElasticSearchRestAPI.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ public void save(String index, ElasticSearchDocument<?> document) throws IOExcep
132132
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
133133

134134
}
135+
136+
/**
137+
* 更新 ES 文档
138+
*
139+
* @param index 索引
140+
* @param document 文档
141+
*/
142+
public void update(String index, ElasticSearchDocument<?> document) throws IOException {
143+
UpdateRequest updateRequest = new UpdateRequest(index, document.getId());
144+
updateRequest.doc(JSON.toJSONString(document.getData()), XContentType.JSON);
145+
146+
restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
147+
}
135148

136149
/**
137150
* 批量保存文档

0 commit comments

Comments
 (0)