开发者学堂课程【ElasticSearch 最新快速入门教程:查询】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/642/detail/10641
查询
内容介绍:
一、ES JavaAPI 查询提纲
二、演示操作
一、提纲
@ Test
public void testGet() {
GetResponse response = client.prepareGet(index, type,”1”).get():
Map<String, Object> map = response.getSource():
System.out.println("version:"+ response.getVersion()}:
for(Map.Entry<String, Object> me: map. entrySet()) {
System.out.printin(me. getKey() + "=" + me.getValue()):
}
二、演示操作
根据特定的 ID 查询索引信息
public void testFindIndexByld() throws IOException {
正式开始使用 Helper 方式新增索引
System.out.println
求出 sourse 的数据
GetResponse response = client.prepareGet(INDEX,TYPE,id“HM9rL2oB300nRXZ6BRB”).get();
Map<String,Object> source = response.getSourse();
一些常用的工具,如:将Map 实例中的值封装到自定义实体类中,前提:map 的 key 的属性名与类的属性名一致
Product bean = new Product()
BeanUtils.populate(new Product(),source);
查询到的索引信息是:+ bean
System.out.println
}
后处理操作,用于进行资源的释放。直接打印 bean 即可
若想封装进去
改名称为 private String last version