之前已将spring boot原生方式介绍了,接下将结介绍的是Elasticsearch聚合操作。聚合操作一般来说是解决一下复杂的业务,比如mysql中的求和和分组,由于博主踩的坑比较多,所以博客可能更多的会介绍这些坑。
一、application.properties配置文件
##端口号 server.port=8880 ##es地址 spring.data.elasticsearch.cluster-nodes =127.0.0.1:9300
二、创建一个Bean层
import org.springframework.data.elasticsearch.annotations.Document; @Document(indexName = "article",type = "center") public class Zoo { private int id; private String animal; private Integer num; private String breeder; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public Integer getNum() { return num; } public void setNum(Integer num) { this.num = num; } public String getBreeder() { return breeder; } public void setBreeder(String breeder) { this.breeder = breeder; } public Zoo(int id, String animal, Integer num, String breeder) { super(); this.id = id; this.animal = animal; this.num = num; this.breeder = breeder; } public Zoo() { super(); } }