ElasticSearch(三)springboot整合ES
最基础的整合:
一、maven依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
二、配置文件application.yml
spring:
data:
elasticsearch:
####集群名称
cluster-name: myes
####地址
cluster-nodes: 192.168.212.xxx:9300
三、实体类UserEntity
@Document(indexName = "mymayikt", type = "user")
@Data
public class UserEntity {
@Id
private String id;
private String name;
private int sex;
private int age;
}
四、dao层代码(实现CrudRepository就可以了,里面封装很多操作ES的方法)
public interface UserReposiory extends CrudRepository<UserEntity, String> {
}
五、controller层
@RestController
public class EsController { @Autowired
private UserReposiory userReposiory; @RequestMapping("/addUser")
public UserEntity addUser(@RequestBody UserEntity user) {
return userReposiory.save(user);
} @RequestMapping("/findUser")
public Optional<UserEntity> findUser(String id) {
return userReposiory.findById(id);
}
}
六、启动类
@SpringBootApplication
@EnableElasticsearchRepositories(basePackages = "com.dyh.dao")
public class AppEs { public static void main(String[] args) {
SpringApplication.run(AppEs.class, args);
}
}
直接启动会报错:
None of the configured nodes are available:
解决方案(项目配置文件cluster-name要与ElasticSearch的配置文件属性值要相同):
Vi /usr/local/elasticsearch-6.4.3/config/elasticsearch.yml
cluster.name: myes
也可以参考这个博客:https://www.cnblogs.com/dalaoyang/p/8990989.html
ElasticSearch(三)springboot整合ES的更多相关文章
- springboot整合es客户端操作elasticsearch(五)
springboot整合es客户端操作elasticsearch的总结: 客户端可以进行可以对所有文档进行查询,就是不加任何条件: SearchRequest searchRequest = new ...
- SpringBoot整合ES+Kibana
前言:最近在写一个HTTP代理服务器,记录日志使用的是ES,所以涉及到SpringBoot和ES的整合,整合完毕后又涉及到数据可视化分析,所以使用了Kibana进行管理,有些坑,需要记录一下 Spri ...
- springboot整合es客户端操作elasticsearch(二)
在上章节中整合elasticsearch客户端出现版本问题进行了处理,这章来进行springboot整合得操作 环境:elaticsearch6.2.1,springboot 2.1.8 客户端版本采 ...
- ElasticSearch(2)---SpringBoot整合ElasticSearch
SpringBoot整合ElasticSearch 一.基于spring-boot-starter-data-elasticsearch整合 开发环境:springboot版本:2.0.1,elast ...
- springboot整合es客户端操作elasticsearch(三)
继续上个随笔: 那么我们只需要修改controller中文件就可以完成相关操作 本次主要是对文档得操作: 更新文档: package com.cxy.elasticsearch.controller; ...
- springboot整合es客户端操作elasticsearch(四)
对文档查询,在实际开发中,对文档的查询也是偏多的,记得之前在mou快递公司,做了一套事实的揽件数据操作,就是通过这个来存储数据的,由于一天的数据最少拥有3500万数据 所以是比较多的,而且还要求查询速 ...
- SpringBoot 整合es(elasticsearch)使用elasticsearch-rest-high-level-client实现增删改
引入依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok< ...
- 【SpringBoot整合Elasticsearch】SpringBoot整合ElasticSearch
一.Linux下安装ElasticSearch 1.检测是否安装了Elasticsearch ps aux |grep elasticsearch 2.安装JDK 3.下载Elasticsearch ...
- SpringBoot操作ES进行各种高级查询
SpringBoot整合ES 创建SpringBoot项目,导入 ES 6.2.1 的 RestClient 依赖和 ES 依赖.在项目中直接引用 es-starter 的话会报容器初始化异常错误,导 ...
随机推荐
- ThinkPHP5使用阿里云OSS图片上传
1.下载OSS文件放在网站根目录下(OSS文件下载地址:https://gitee.com/jth1234/oss_files.git) 2.在入口文件中加载OSS 3.config文件配置oss信息 ...
- Matlab矩阵间快速赋值方法
目前还没见到网上用过这个简单的方式 A= [1 2 3; 4 5 6; 7 8 9] B = zeros(5,5) B(1:3, 2:4) = A %将A赋值到B的第1行到3行,第2列岛4列, ...
- P2220 [HAOI2012]容易题【快速幂】
题目描述 为了使得大家高兴,小Q特意出个自认为的简单题(easy)来满足大家,这道简单题是描述如下: 有一个数列A已知对于所有的A[i]都是1~n的自然数,并且知道对于一些A[i]不能取哪些值,我们定 ...
- NXP S32V eiq_auto tensorflow offline tool 环境配置
NXP S32V eiq_auto tensorflow offline tool 环境配置 完成cnn模型eiq移植的第一步 1.安装conda 下载.sh bash Anaconda3-5.3.1 ...
- HotSpot项目结构
之前已经介绍了在Ubuntu 16.04上编译OpenJDK8的源代码和调试HotSpot源代码.这一章将介绍HotSpot项目的目录结构. HotSpot目录下主要由agent.make.src和t ...
- 详解GaussDB bufferpool缓存策略,这次彻底懂了!
摘要:华为云GaussDB(for mysql)是华为云自主研发的最新一代云原生数据库,采用计算存储分离.日志即数据的架构设计.具备极致可靠.极致性价比.多为扩展.完全可信等诸多特性. 一 .Gaus ...
- C++中复杂声明和定义的辨析
0x00 前言 c++中的复杂声明往往令人无法下手,经常使人搞错这到底声明的是一个指针还是指针函数.但其实c++对于复杂声明是遵循一定的规则的,叫做变量名—>右--左-右规则. 0x01 规则解 ...
- Jenkins 自动化(CI/DI)部署
1. 背景介绍 在实际开发中,经常要一边开发一边测试,经常为了一个功能而不断更新版本,这些情况都会涉及到频繁的打包.部署:手动打包的涉及到项目上传.打包.发布等很多重复工作: 那么,有一种工具能够实现 ...
- 安装更强大更美观的zsh,配置oh my zsh及插件
安装更强大更美观的zsh,配置oh my zsh及插件 #0x0 安装zsh #0x1 安装oh my zsh #0x2 配置zshrc #0x3 配置主题 #0x4 安装插件 #0x5 小结 #0x ...
- sql 增加修改表格属性字段
1.修改字段默认值 alter table 表名 drop constraint 约束名字 ------注解:删除表的字段的原有约束 alter table 表名 add constraint 约束名 ...