spring boot elasticsearch 的基本配置和使用方法:

完整项目代码基本实现流程:

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>
             &lt;!&ndash;            <version>4.1.1</version>&ndash;&gt;
         </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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

specialApe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值