怎么搭建Elasticsearch服务就不多说了,可参考:
Elasticsearch5.2.1集群搭建 https://blog.youkuaiyun.com/Gamer_gyt/article/details/59077189
1.添加配置及依赖
spring:
data:
elasticsearch:
cluster-name: es
cluster-nodes: 192.168.120.103:9300,192.168.120.104:9300
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-elasticsearch:1.5.8.RELEASE'
}
2.实体类,定义索引、类型、字段
package com.demo.pojo;
import java.io.Serializable;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
@Document(indexName = "apilog_index", type = "apilog")
public class ApiLog implements Serializable {
private static final long serialVersionUID = -3823181217