开发者学堂课程【ElasticSearch 最新快速入门教程:更新】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/642/detail/10642
更新
内容介绍:
一、更新提纲
二、演示操作
一、更新提纲
@ Test
public void testUpdate() throws Exception {
XContentBuilder source = XContentFactory.jsonBuilder()
.startObject()
field("name","hadoop")
field("author","CDH")
field("version", 2.7)
endObject();
client.prepareUpdate(index, type, "1").setDoc(source).get():
testGet();
}
二、演示操作
@ Test
public void testUpdate() throws Exception {
需求:针对索引库 bigdata 中的 type 之 product,将 id 为 OiUhuGkBJFmjDtb2b5的 document 的 name 更新为“独孤求败”,version 更新为1.6.5 (局部更新)
UpdateResponseresponse= client.prepareUpdate(“bigdata”,“product”,“OiUhuGkBJFmjDtb2b5”)
.setDoc(“name”,“独孤求败”,“version”,“1.6.5”)
.get();
logger.info(“获得了来自远程es集群的反馈信息是 :”+response);
需求:测试根据特定的id更新索引信息
描述:
针对索引库 bigdata 中 type 之 product,
将 id 为 OiUhuGkBJFmjDtb2b5的 document 的 name 更新为“SQOOP”,version 更新为1.6.5 (局部更新)
public void testUpdate() Byld(){
UpdateResponseresponse =client.prepareUpdate(INDEX,TYPE,“OiUhuGkBJFmjDtb2b5”)
.setDoc(“SQOOP”,“1.6.5”),XContentType.JSON)
.get();
System.out.println(“更新之后的反馈信息是:” + response);
}