Spring boot中使用ElasticSearch的方法详解

论坛 期权论坛 脚本     
niminba   2021-5-23 02:49   808   0

0.版本选择

我这里选择了5.6.x,记得如果spring-boot-starter-parent是1.x可以选择2.x版本的elasticsearch,版本要对应,不然会有莫名其妙的问题

1.安装ElasticSearch

https://www.elastic.co/downloads/past-releases

windows 测试的,解压就能用

解压,到bin目录,双击elasticsearch.bat

1.1安装elasticsearch-head

https://github.com/mobz/elasticsearch-head

elasticsearch-head是一个网页查看elasticsearch状态,操作的第三方东西

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
open http://localhost:9100/

要先安装node.js

config/elasticsearch.yml 文件增加

http.cors.enabled: true
http.cors.allow-origin: “*”

elasticsearch-head/Gruntfile.js

connect: {
   server: {
    options: {
     hostname: '0.0.0.0',
     port: 9100,
     base: '.',
     keepalive: true
    }
   }
  }

8082改成你自己的端口

http://127.0.0.1:8082/swagger-ui.html#/

0是第一页

application.properties

#===es start===
spring.data.elasticsearch.repositories.enabled = true
spring.data.elasticsearch.cluster-nodes = 127.0.0.1:9300
#===es end===

2.porm

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.1.1.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <groupId>com.example</groupId>
 <artifactId>demo</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>demo</name>
 <description>Demo project for Spring Boot</description>
 <packaging>jar</packaging>
 
 <properties>
  <java.version>1.8</java.version>
 </properties>
 
 <dependencies>
  <!--Swagger-UI API文档生产工具-->
  <dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.6.1</version>
  </dependency>
  <dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version$	РРРР4(4(I	I55P4(=VN4(%QVNхQ4(=IA=	4(MEMEЁ9M
ХAI9MEE9ME	EME
ФAE4(I	I55P4(=BsVN4(1IA%9IAMMEEME9AEР4)4(顽ё屔еɑе5Ёeɑ聹ɑе聹ее屔聹е聱ɑ聹еееее聹еее屔聥е4(屔4(bZj3rorZj疾疒j惚"[r'kj>惒zsr'ZG^>Vg瞒jR2
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP