springboot集成elasiticsearch

springboot集成elasiticsearch

1、版本选择
springboot2.2.2
elasiticsearch6.7.1
2、centos7安装elasiticsearch6.7.1
  • centos7安装elasiticsearch6.7.1
    elasiticsearch下载:elasiticsearch下载

     如果虚拟机可以联网,可以直接下载:
     wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.1.zip
    
  • 将下载好的zip文件上传到linux的/opt目录下,然后解压:

	unzip  elasticsearch/elasticsearch-6.7.1.zip
	mv elasticsearch-6.7.1  es6.7
  • 进入es6.7中,修改elasticsearch.yml文件
    为了能让Elasticsearch-head访问,添加如下内容(Elasticsearch-head可以去githup下载,下载后解压直接打到index.html):
	http.cors.enabled: true
	http.cors.allow-origin: "*"
	去掉#http.port: 9200的注释,将端口修改为9500(也可以不修改)
	http.port: 9500
	启动elasticsearch
		进入到es6.7下
			cd  es6.7/
			./bin/elasticsearch
  • 如果启动成功,有如下标志
    启动成功

  • 测试,使用命令 curl http://localhost:9500测试
    在这里插入图片描述

3、使用Elasticsearch-head连接
打开Elasticsearch-head的index.html,输入地址,如果出现如下画面,连接成功

在这里插入图片描述

4、springboot集成elasticsearch
  • 引入依赖
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
  • yml配置
	server:
	  port: 8080
	
	spring:
	  mvc:
	    view:
	      prefix: /static/*
	      suffix: .html
	
	  datasource:
	    driver-class-name: com.mysql.cj.jdbc.Driver
	    url: jdbc:mysql://localhost:3306/sunny
	    username: root
	    password: root
	
	  data:
	    elasticsearch:
	      cluster-name: elasticsearch
	      cluster-nodes: 192.168.101.11:9300
  • 创建实体类

	
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值