赞
踩
我们做一个类似于 update stu set sign='abc',age=33,money=88.6 where docId='1002'
的操作
@Test public void updateStuDoc() { Map<String, Object> sourceMap = new HashMap<>(); sourceMap.put("sign", "I am not super man"); sourceMap.put("money", 88.6f); sourceMap.put("age", 33); IndexRequest indexRequest = new IndexRequest(); indexRequest.source(sourceMap); UpdateQuery updateQuery = new UpdateQueryBuilder() .withClass(Stu.class) .withId("1003") .withIndexRequest(indexRequest) .build(); esTemplate.update(updateQuery); }
我们查看一下结果,能看到数据已经修改成功了!
类似于select * from stu where docId='1002'
@Test
public void getStuDoc() {
GetQuery query = new GetQuery();
query.setId("1002");
Stu stu = esTemplate.queryForObject(query, Stu.class);
System.out.println(stu);
}
能看到打印结果
类似于delete from stu where docId='1002'
@Test
public void deleteStuDoc() {
esTemplate.delete(Stu.class, "1002");
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。