SpringBoot2.0之整合ElasticSearch
就类比数据库到时候去实现
服务器端配置 集群名字 与yml名字一致

pom:
<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>
<groupId>com.toov5</groupId>
<artifactId>springboot-es</artifactId>
<version>0.0.1-SNAPSHOT</version> <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>
<!-- springboot 整合es -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies> </project>
项目结构:

Entity:
package com.toov5.entity; import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; import lombok.Data; @Document(indexName="toov5",type="user") //索引的名字 类型
@Data
public class UserEntity {
@Id
private String id;
private String name;
private Integer age;
private Integer sex;
}
Dao:
package com.toov5.dao;
import org.springframework.data.repository.CrudRepository;
import com.toov5.entity.UserEntity;
public interface UserDao extends CrudRepository<UserEntity, String> {
}
Controller:
package com.toov5.controller; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.toov5.dao.UserDao;
import com.toov5.entity.UserEntity; @RestController
public class EsController { @Autowired
private UserDao userDao; //添加文档
@RequestMapping("/addUser")
public UserEntity addUser(@RequestBody UserEntity userEntity) {
return userDao.save(userEntity);
} //查询文档
@RequestMapping("/findById")
public Optional<UserEntity> findById(String id) {
return userDao.findById(id);
} }
成功:

查看:

查询:

SpringBoot2.0之整合ElasticSearch的更多相关文章
- SpringBoot2.0之整合Kafka
maven依赖: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...
- SpringBoot2.0之整合Apollo
Spring Boot客户端对接阿波罗服务器端 核心源码都在这个压缩包里面 封装好了环境 运行shell脚本就ok了 下面进入到本地maven仓库: 远程仓库apollo的jar包 只能打包到本地或者 ...
- SpringBoot2.0之整合ActiveMQ(发布订阅模式)
发布订阅模式与前面的点对点模式很类似,简直一毛一样 注意:发布订阅模式 先启动消费者 公用pom: <project xmlns="http://maven.apache.org/PO ...
- SpringBoot2.0之整合ActiveMQ(点对点模式)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- SpringBoot2.0之整合Dubbo
Dubbo支持协议 Dubbo支持dubbo.rmi.hessian.http.webservice.thrift.redis等多种协议,但是Dubbo官网是推荐我们使用Dubbo协议的. Sprin ...
- 基于 SpringBoot2.0+优雅整合 SpringBoot+Mybatis
SpringBoot 整合 Mybatis 有两种常用的方式,一种就是我们常见的 xml 的方式 ,还有一种是全注解的方式.我觉得这两者没有谁比谁好,在 SQL 语句不太长的情况下,我觉得全注解的方式 ...
- springboot2.0 Mybatis 整合
原文:https://blog.csdn.net/Winter_chen001/article/details/80010967 环境/版本一览: 开发工具:Intellij IDEA 2017.1. ...
- 每天学点SpringCloud(一):使用SpringBoot2.0.3整合SpringCloud
最近开始学习SpringCloud,在此把我学习的过程记录起来,跟大家分享一下,一起学习.想学习SpringCloud的同学赶快上车吧. 本次学习使用得SpringBoot版本为2.0.3.RELEA ...
- springboot2.0+dubbo整合分布式服务发布和调用
最近项目上要对以前的老项目做分布式的整改,因此我专门花了点时间研究下当前比较热门的dubbo和springboot结合使用,以前使用过dubbo,但是没有与springboot结合过,在网上查了点资料 ...
随机推荐
- iOS UIModalPresentationFormSheet风格下的键盘隐藏
1. 在UIModalPresentationFormSheet(iPad device, without a UINavigationController)下的视图中,如果使用 [inputView ...
- jquery刷新页面指定部位
做好好几次了,经常忘记格式,这次记下来 $("#baseInfo").load("/KnowledgeLib/Personalization/QuestionUpdate ...
- 三种系统监控工具对比:top vs Htop vs Glances
首先启用 EPEL Repository: yum -y install epel-release 启用 EPEL Repository 後, 可以用 yum 直接安裝 Htop: yum -y in ...
- Struts2 框架的值栈
1. OGNL 表达式 1.1 概述 OGNL(Object Graphic Navigation Language),即对象图导航语言; 所谓对象图,即以任意一个对象为根,通过OGNL可以访问与这个 ...
- 解决 pip 安装opendr包 卡住的问题
使用豆瓣的源(已经确认过了该源中有opendr包),pip安装opendr,结果卡在了下载完成的位置,什么提示也没有.(如下图) 既然安装包已经下载下来了又安装不上,则应该是安装代码中有什么问题,只不 ...
- TouchDelegate
TouchDelegate(Rect bounds, View delegateView) Parameters: bounds Bounds in local coordinates of the ...
- mysql 内置功能 函数 date_format函数
创建数据库db12 create database db12 charset=utf8; use db12; 准备表和记录 CREATE TABLE blog ( id INT PRIMARY KEY ...
- TypeScript学习笔记—函数
函数定义 在 JavaScript 中,有两种常见的定义函数的方式——函数声明(Function Declaration)和函数表达式(Function Expression): // 函数声明(Fu ...
- git常用命令总结(转载)
Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remote:远程仓库 一.新建代码库 # 在当前目录新建一个Git代码库 $ git in ...
- n个数里选出m个不重复的数
void change(int *p,int a,int b) { int tmp = *(p + a); *(p + a) = *(p + b); *(p + b) = tmp; } int mai ...