Springboot整合ElasticSearch进行简单的测试及用Kibana进行查看
一、前言
搜索引擎还是在电商项目、百度、还有技术博客中广泛应用,使用最多的还是ElasticSearch,Solr在大数据量下检索性能不如ElasticSearch。今天和大家一起搭建一下,小编是看完雷神的视频,自己来整理一遍,增加一下自己的记忆。所有版本就以ElasticSearch7.4.2来进行测试,如果ElasticSearch还没有安装的同学可以看一下我的这篇文章,搭建一下哦!!
使用Docker安装ElasticSearch和可视化界面Kibana
二、创建SpringBoot项目
1. 使用默认构建

2. 配置项目基本信息

3. 引入基本依赖

4. 指定保存位置

三、配置ElasticSearch
1. 打开官方文档
2. 根据官方文档进行配置

3. 新建配置类
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ElasticSearchConfig {
@Bean
public RestHighLevelClient elasticSearchClient(){
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
//我们不是集群,所有只配置一个,地址填你ES的运行在的主机地址
new HttpHost("192.168.17.130", 9200, "http")));
return client;
}
}
4. 根据官网进行自己扩展

四、新建索引测试
1. 官方文档例子很多,我们挑选一个最简单的进行测试


2. 测试类书写
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
import java.util.Date;
@SpringBootTest
class DemoApplicationTests {
//引入ESclient
@Autowired
private RestHighLevelClient client;
@Test
void contextLoads() throws IOException {
//构建
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
{
builder.field("user", "kimchy");
builder.timeField("postDate", new Date());
builder.field("message", "trying out Elasticsearch");
}
builder.endObject();
IndexRequest indexRequest = new IndexRequest("posts")//索引名字
.id("1")//数据存储的id,不行默认随机生成
.source(builder);//存放数据
//执行操作
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
System.out.println(indexRequest);
}
}
3. 控制台打印正常

五、使用kibana查看
登录kibana并查看(http://192.168.17.130:5601/)

六、总结
这样我们就完整了Springboot整合ElasticSearch进行简单的测试及用Kibana进行查看,内容不多,一切以官网为准,我们安装官网是不会有问题的。除非有版本问题,目前小编的ElasticSearch是7.4.2,但是SpringBoot是最新的2.6.3,也没有出现版本冲突的问题!!
推广自己网站时间到了!!!
Springboot整合ElasticSearch进行简单的测试及用Kibana进行查看的更多相关文章
- SpringBoot整合ElasticSearch实现多版本的兼容
前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...
- ElasticSearch(2)---SpringBoot整合ElasticSearch
SpringBoot整合ElasticSearch 一.基于spring-boot-starter-data-elasticsearch整合 开发环境:springboot版本:2.0.1,elast ...
- springBoot整合MyBatise及简单应用
springBoot整合MyBatise及简单应用 我采用的是 工具IDEA 框架是springBoot+maven+Mybatise 第一步: pom.xml 引入相关jar包 <?xml v ...
- SpringBoot整合Elasticsearch详细步骤以及代码示例(附源码)
准备工作 环境准备 JAVA版本 java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121 ...
- 😊SpringBoot 整合 Elasticsearch (超详细).md
SpringBoot 整合 Elasticsearch (超详细) 注意: 1.环境搭建 安装es Elasticsearch 6.4.3 下载链接 为了方便,环境使用Windows 配置 解压后配置 ...
- springboot整合elasticsearch入门例子
springboot整合elasticsearch入门例子 https://blog.csdn.net/tianyaleixiaowu/article/details/72833940 Elastic ...
- Springboot整合elasticsearch以及接口开发
Springboot整合elasticsearch以及接口开发 搭建elasticsearch集群 搭建过程略(我这里用的是elasticsearch5.5.2版本) 写入测试数据 新建索引book( ...
- Springboot整合Elasticsearch报错availableProcessors is already set to [4], rejecting [4]
Springboot整合Elasticsearch报错 今天使用SpringBoot整合Elasticsearch时候,相关的配置完成后,启动项目就报错了. nested exception is j ...
- 从无到有Springboot整合Spring-data-jpa实现简单应用
本文介绍Springboot整合Spring-data-jpa实现简单应用 Spring-data-jpa是什么?这不由得我们思考一番,其实通俗来说Spring-data-jpa默认使用hiberna ...
随机推荐
- pytest用例的执行顺序
Pytest执行的顺序 当pytest运行测试函数时,它会查看该测试函数中的参数,然后搜索与这些参数具有相同名称的fixture.一旦pytest找到这些对象,它就会运行这些fixture 影响执行顺 ...
- Selenium_单选框和复选框的选中状态判定以及元素是否可用和可见判定(10)
简单写个单选框和复选框界面 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /&g ...
- Visual Studio Code快速补全html标签(Sublime同样支持)
1.生成html文件骨架 输入"!" 或 "html:5",按tab键 注意:编写中文网页,记得把头部语言<html lang="en" ...
- spring boot --- 注解 @Bean 和@Component
1.前言 @Bean是给方法注册bean @Component是给不好归类的类注册bean 2.可以达到一样的效果 (1)@Component 直接注册即可 完整源码 package com.exam ...
- ASCII、Unicode和UTF-8等常见字符编码格式介绍
信息存储在计算机中是转换成二进制来存储的,二进制的发明据说是来源于中国阴阳八卦.后德国数理哲学大师莱布尼茨是最早接触中华文化的欧洲人之一,从他的传教士朋友鲍威特寄给他的拉丁文译本<易经>中 ...
- 【解决了一个小问题】golang中引用一个路径较长的库,导致goland中出现"module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2"
在项目中的go.mod文件中有这样一句: require ( github.com/xxx-devops/xx1/sdk/go v2.2.3 ) 项目的编译没有问题,但是goland中出现如下提示: ...
- NAO机器人开发环境配置
python python2.7用于NAO开发 https://www.python.org/downloads/release/python-2718/ python3.6用于其他程序测试. htt ...
- Cesium入门11 - Interactivity - 交互性
Cesium入门11 - Interactivity - 交互性 Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ ...
- elasticsearch之请求处理流程(Rest/RPC )
.Action概述 ES提供client供集群节点或java客户端访问集群用.client模块通过代理模式,将所有的操作都集成到client接口中.这样外部调用只需要初始化client就能够完成所有的 ...
- 关于网页中鼠标动作 onfocus onblur focus()
其中: onFocus事件就是当光标落在文本框中时发生的事件. onBlur事件是光标失去焦点时发生的事件. 例如: <textarea onfocus="if(hello') {va ...