在之前的课时中我们优化查询效率一共有两个方面,一是对于 query 查询,如果想要一次性取大量数据,我们选择使用 Scroll 查询。当碰到聚合数据过大时候,我们介绍了两种一种是 Partition 查询,一种是 Composite 查询。本节课中将会对以上的优化方式做一个 Java 的实现。
Scroll 查询
给定需求:查询天气索引中北京地区的所有数据。
Java 中一切皆是对象,所以对于返回的天气数据最后中一个创建一个对于的 bean 类。
public class weather {
private String city;
private int temperature;
private Date timestamp;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getTemperature() {
return temperature;
}
public void setTemperature(int temperature) {
this.temperature = temperature;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
}
定义 weather_monitor 索引,设置 term 查询,字段设置成 city,条件设置成 bei