一、前言

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

使用Docker安装ElasticSearch和可视化界面Kibana

二、创建SpringBoot项目

1. 使用默认构建



2. 配置项目基本信息



3. 引入基本依赖



4. 指定保存位置

三、配置ElasticSearch

1. 打开官方文档

ElasticSearch官网文档

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进行查看的更多相关文章

  1. SpringBoot整合ElasticSearch实现多版本的兼容

    前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...

  2. ElasticSearch(2)---SpringBoot整合ElasticSearch

    SpringBoot整合ElasticSearch 一.基于spring-boot-starter-data-elasticsearch整合 开发环境:springboot版本:2.0.1,elast ...

  3. springBoot整合MyBatise及简单应用

    springBoot整合MyBatise及简单应用 我采用的是 工具IDEA 框架是springBoot+maven+Mybatise 第一步: pom.xml 引入相关jar包 <?xml v ...

  4. SpringBoot整合Elasticsearch详细步骤以及代码示例(附源码)

    准备工作 环境准备 JAVA版本 java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121 ...

  5. 😊SpringBoot 整合 Elasticsearch (超详细).md

    SpringBoot 整合 Elasticsearch (超详细) 注意: 1.环境搭建 安装es Elasticsearch 6.4.3 下载链接 为了方便,环境使用Windows 配置 解压后配置 ...

  6. springboot整合elasticsearch入门例子

    springboot整合elasticsearch入门例子 https://blog.csdn.net/tianyaleixiaowu/article/details/72833940 Elastic ...

  7. Springboot整合elasticsearch以及接口开发

    Springboot整合elasticsearch以及接口开发 搭建elasticsearch集群 搭建过程略(我这里用的是elasticsearch5.5.2版本) 写入测试数据 新建索引book( ...

  8. Springboot整合Elasticsearch报错availableProcessors is already set to [4], rejecting [4]

    Springboot整合Elasticsearch报错 今天使用SpringBoot整合Elasticsearch时候,相关的配置完成后,启动项目就报错了. nested exception is j ...

  9. 从无到有Springboot整合Spring-data-jpa实现简单应用

    本文介绍Springboot整合Spring-data-jpa实现简单应用 Spring-data-jpa是什么?这不由得我们思考一番,其实通俗来说Spring-data-jpa默认使用hiberna ...

随机推荐

  1. 第10组 Alpha冲刺 (2/6)

    1.1基本情况 ·队名:今晚不睡觉 ·组长博客:https://www.cnblogs.com/cpandbb/ ·作业博客:https://edu.cnblogs.com/campus/fzu/FZ ...

  2. Golang中Label的用法

    在Golang中能使用Label的有goto, break, continue.,这篇文章就介绍下Golang中Label使用和注意点. 注意点: Label在continue, break中是可选的 ...

  3. 机器学习&恶意代码动态检测

    目录 写在前面 1 基于API调用的统计特征 2 API序列特征 3 API调用图 4 基于行为的特征 references: 写在前面 对恶意程序动态检测方法做了概述, 关于方法1和2可以参考阿里云 ...

  4. Cesium入门4 - 创建Cesium Viewer

    Cesium入门4 - 创建Cesium Viewer Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ 任何Ce ...

  5. golang中的定时器

    1.  timer 定时器,时间到了执行,只执行一次 package main import ( "fmt" "time" ) func main() { // ...

  6. Go 结构体方法

    #### Go 结构体方法本来今天有些事情忙的不准备更新内容了,后来提前完成了, 所以还是要更新了; 毕竟坚持本就是一件不容易的事情!加油,相信不管是大家还是我,都有一些事情想要做,那就坚持吧,剩下的 ...

  7. 【Azure 应用服务】Azure Mobile App (NodeJS) 的服务端部署在App Service for Windows中出现404 Not Found -- The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    问题描述 使用NodeJS的后端应用,开发一个Mobile App的服务端,手机端通过REST API来访问获取后端数据.在本地编译好后,通过npm start启动项目,访问效果如下: 但是,当把项目 ...

  8. Python中的魔术方法

    什么是魔术方法? 在Python中,所有用"__"包起来的方法,都称为[魔术方法]. 魔术方法一般是为了让显示器调用的,你自己并不需要调用它们. __init__:初始化函数 这个 ...

  9. 关于老Windows平板电脑睡眠状态下无法开机(睡死)的问题及解决方案

    1.简述 前几天我从闲鱼上淘了一个二手Windows平板, 拿来上课记笔记用. 型号是联想的Thinkpad Helix 2nd, 2015年出产. cpu是酷睿m-5y71超低功耗处理器, TDP只 ...

  10. idea2020.1版本的maven项目报包不存在,找不到包错误

    错误描述 idea创建maven项目,导入依赖都是成功,但是运行就会报找不到对应jar包的错误 解决办法: File -> Settings -> 搜索maven -> 展开mave ...