elasticsearch java api 增删改 操作

作者: qq123   发布时间:2016-06-08
es
--添加数据
IndexRequestBuilder requestBuilder = null;
requestBuilder = client.prepareIndex(index, type, key).setRefresh(false);
requestBuilder.setSource(value).get();

--批量数据
BulkRequestBuilder bulkRequest = null;
bulkRequest = client.prepareBulk();
for (Map.Entry<String, Object> map : doc.entrySet()) {
bulkRequest.add(client.prepareIndex(index, type, map.getKey())
.setSource(CouchbaseUtil.GJSON.toJson(map.getValue())).setRefresh(false));
}
bulkRequest.get();
bulkRequest.request().requests().clear();

--更新数据
client.prepareUpdate().setIndex(index).setType(type).setId(id).setDoc(map).get();

--批量删除数据
BulkRequestBuilder bulk = null;
bulk = client.prepareBulk();
for (String id : ids) {
bulk.add(client.prepareDelete().setIndex(index).setType(type).setId(id));
}
bulk.get();

0 个评论

要回复文章请先登录注册