0
点赞
收藏
分享

微信扫一扫

Elasticsearch insert & update

zhyuzh3d 2022-04-18 阅读 102
java后端

使用RestHighLevelClient 更新操作 经验

使用 同一个 index 、type 进行 insert 操作时 可以进行整体更新操作,比局部更新方便

使用局部更新时使用Map 进行可对局部字段进行更新

核心代码:

当插入相同的 index 、type es 会根据id 进行覆盖 下面的代码可以对相同id 的document 进行局部和整体更新

JSONObject json = (JSONObject) JSONObject.parse(object);

entity = new NStringEntity(json.toJSONString(), ContentType.APPLICATION_JSON);

String index = json.getString(“index_type”);

String id = json.getString(“id”);

client.performRequest(“PUT”, “/” + index + “/” + index + “/” + id, Collections.emptyMap(), entity);

此前使用 Map 局部更新时需要对json中的每一个key 进行覆盖 ---- 之前也是这么做的

举报

相关推荐

0 条评论