完整项目代码基本实现流程:
1.mysql的相关链接
2.es的相关依赖
3.本地启动es,fastjson进行插入的操作!
1.SkuEsMapper extends ElasticsearchRepository<SkuInfo,Long>
2.mapper.saveall()
4.kibana或者head可视化进行查看测试结果!
5.read.me中查看对应的sql文件和操作流程!
6.简单得搜索的流程!
尚硅谷的参考教程:
https://www.bilibili.com/video/BV1Et411Y7tQ?p=93
笔记:
package com.example.demo;
import io.searchbox.client.JestClient;
import io.searchbox.core.Index;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.io.IOException;
@SpringBootTest
class DemoApplicationTests {
@Resource
JestClient jestClient;
@Test
void contextLoads() throws IOException {
Pojo pojo = new Pojo();
pojo.setId(234);
pojo.setName("刘育超");
Index index = new Index.Builder(pojo).index("test").type("news").build();
jestClient.execute(index);
}
}
@Setter
@Getter
public class Pojo {
private Integer id;
private String name;
}
对应的依赖:
<!-- 注意;springdata 和对应的jest是不同依赖,需要分开使用哦-->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<!– <version>4.1.1</version>–>
</dependency>-->
<!-- https://mvnrepository.com/artifact/io.searchbox/jest -->
<dependency>
<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
<version>5.3.3</version>
</dependency>
问题,执行出错:暂时未解决!
@autowired jestclient直接就报红
@resource 执行结束报红,
参考文章:
SpringBoot应用整合ELK实现日志收集
唱购的demo
对应的版本适配的矩阵的参考地址:
https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.versions
https://docs.spring.io/spring-data/elasticsearch/docs/3.2.6.RELEASE/reference/html/#reference
官方的demo下载地址:
https://github.com/spring-projects/spring-data-examples