本文springboot版本为2.2.6,使用spring-boot-2.1.4会失败
1. pom.xml引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
<scope>compile</scope>
</dependency>
2. application.yml配置es信息
spring:
jpa:
show-sql: true
elasticsearch:
rest:
uris: http://localhost:9200
username: user
password: pwd
3. UserService
package com.es.test.service;
import com.alibaba.fastjson.JSONObject;
import com.es.test.repository.UserRepository;
import com.es.test.model.Us