当前位置:   article > 正文

SpringBoot项目中如何往elasticseach索引库导入数据_springboot数据同步到elasticsearch

springboot数据同步到elasticsearch

目录

新建模块

1.新建一个maven模块 

2.导入maven依赖

3.配置yml文件

4.新建引导类

新增实体类

1.新增实体类,并设置映射

使用Feign调用所需要的服务

存取map

把查询到的信息存入索引库

1.新建一个repository操作接口

2.新建测试类

3.重启微服务,启动测试方法


 

新建模块

 

1.新建一个maven模块 

设置文件路径

 

 

2.导入maven依赖

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <parent>
  6. <artifactId>leyou</artifactId>
  7. <groupId>com.leyou.parent</groupId>
  8. <version>1.0.0-SNAPSHOT</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11. <groupId>com.leyou.search</groupId>
  12. <artifactId>leyou-search</artifactId>
  13. <version>1.0.0-SNAPSHOT</version>
  14. <dependencies>
  15. <dependency>
  16. <groupId>org.springframework.cloud</groupId>
  17. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.springframework.boot</groupId>
  21. <artifactId>spring-boot-starter-web</artifactId>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.springframework.cloud</groupId>
  25. <artifactId>spring-cloud-starter-openfeign</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
  30. </dependency>
  31. <dependency>
  32. <groupId>com.leyou.item</groupId>
  33. <artifactId>leyou-item-interface</artifactId>
  34. <version>1.0.0-SNAPSHOT</version>
  35. </dependency>
  36. <dependency>
  37. <groupId>com.leyou.common</groupId>
  38. <artifactId>leyou-common</artifactId>
  39. <version>1.0.0-SNAPSHOT</version>
  40. </dependency>
  41. <dependency>
  42. <groupId>org.springframework.boot</groupId>
  43. <artifactId>spring-boot-starter-test</artifactId>
  44. </dependency>
  45. </dependencies>
  46. </project>

 

3.配置yml文件

  1. server:
  2. port: 8083
  3. spring:
  4. application:
  5. name: search-service
  6. data:
  7. elasticsearch:
  8. cluster-name: elasticsearch
  9. cluster-nodes: 192.168.62.128:9300
  10. eureka:
  11. client:
  12. service-url:
  13. defaultZone: http://127.0.0.1:10086/eureka
  14. registry-fetch-interval-seconds: 10
  15. instance:
  16. lease-renewal-interval-in-seconds: 5
  17. lease-expiration-duration-in-seconds: 15

 

4.新建引导类


                
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/936268
推荐阅读
相关标签
  

闽ICP备14008679号