========================12章 搜索框架ElasticSearch介绍和整合SpringBoot =============================

加入小D课堂技术交流答疑群:Q群:699347262

1、搜索引擎知识和搜索框架elasticsearch基本介绍
简介:通过京东电商 介绍什么是搜索引擎,和开源搜索框架ElasticSearch6.x新特性介绍

前言:介绍ES的主要特点和使用场景,新特性讲解
mysql:like 模糊,性能问题,

solr:针对企业,Lucene
elasticsearch:针对数据量特别大,PB,TB
纯java开发,springboot使用,5.6版本
es升级4->5版本,改动大,但是5版本后,改动不大

elasticSearch主要特点

1、特点:全文检索,结构化检索,数据统计、分析,接近实时处理,分布式搜索(可部署数百台服务器),处理PB级别的数据
搜索纠错,自动完成
2、使用场景:日志搜索,数据聚合,数据监控,报表统计分析

3、国内外使用者:维基百科,Stack Overflow,GitHub

新特性讲解

1、6.2.x版本基于Lucene 7.x,更快,性能进一步提升,对应的序列化组件,升级到Jackson 2.8
mysql:database table rocord
es : index type(只能存在一个) document

2、推荐使用5.0版本推出的Java REST/HTTP客户端,依赖少,比Transport使用更方便,在基准测试中,性能并不输于Transport客户端,

在5.0到6.0版本中,每次有对应的API更新, 文档中也说明,推荐使用这种方式进行开发使用,所有可用节点间的负载均衡
在节点故障和特定响应代码的情况下进行故障转移,失败的连接处罚(失败的节点是否重试取决于失败的连续次数;失败的失败次数越多,客户端在再次尝试同一节点之前等待的时间越长)

3、(重要)不再支持一个索引库里面多个type,6.x版本已经禁止一个index里面多个type,所以一个index索引库只能存在1个type

官方文档:
1、6.0更新特性
https://www.elastic.co/guide/en/elasticsearch/reference/6.0/release-notes-6.0.0.html#breaking-java-6.0.0
2、6.1更新特性
https://www.elastic.co/guide/en/elasticsearch/reference/6.1/release-notes-6.1.0.html

2、快熟部署ElastcSearch5.6.x
简介:讲解为什么不用ES6.x版本,及本地快速安装ElasticSeach和场景问题处理

配置JDK1.8
使用wget 下载elasticsearch安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.tar.gz
解压
tar -zxvf elasticsearch-5.6.8.tar.gz
官网:https://www.elastic.co/products/elasticsearch

windows下开启

外网访问配置:
config目录下面elasticsearch.yml
修改为 network.host: 0.0.0.0

配置es出现相关问题处理(阿里云、腾讯云,亚马逊云安装问题集合):
1、问题一
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/software/temp/elasticsearch-6.2.2/hs_err_pid1912.log
解决:内存不够,购买阿里云的机器可以动态增加内存

2、问题二
[root@iZwz95j86y235aroi85ht0Z bin]# ./elasticsearch
[2018-02-22T20:14:04,870][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.2.jar:6.2.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.2.jar:6.2.2]
解决:用非root用户
添加用户:useradd -m 用户名 然后设置密码 passwd 用户名

3、问题三
./elasticsearch
Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/software/temp/elasticsearch-6.2.2/config/jvm.options
解决:权限不够 chmod 777 -R 当前es目录

常见配置问题资料:https://www.jianshu.com/p/c5d6ec0f35e0

3、ElasticSearch5.6.8测试数据准备
简介: ElasticSearch5.6.x简单测试
1、步骤 https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index.html
2、使用POSTMAN 工具

基础
查看集群状态:localhost:9200/_cat/health?v
查看索引列表:localhost:9200/_cat/indices?v

4、SpringBoot2.x整合elasticsearch5.6.x
简介:SpringBoot2.x整合elasticSearch5.6.8实战

Spring Data Elasticsearch文档地址
https://docs.spring.io/spring-data/elasticsearch/docs/3.0.6.RELEASE/reference/html/

版本说明:SpringBoot整合elasticsearch
https://github.com/spring-projects/spring-data-elasticsearch/wiki/Spring-Data-Elasticsearch---Spring-Boot---version-matrix

版本差异:

1、添加maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>

2、接口继承ElasticSearchRepository,里面有很多默认实现
注意点:
索引名称记得小写,类属性名称也要小写
新建实体对象article
加上类注解 @Document(indexName = "blog", type = "article")

3、配置文件:
# ELASTICSEARCH (ElasticsearchProperties)
spring.data.elasticsearch.cluster-name=elasticsearch # Elasticsearch cluster name.
spring.data.elasticsearch.cluster-nodes=localhost:9300 # Comma-separated list of cluster node addresses.
spring.data.elasticsearch.repositories.enabled=true # Whether to enable Elasticsearch repositories.

4、QueryBuilder使用
https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.3/query-dsl-queries.html

//单个匹配,搜索name为jack的文档
QueryBuilder queryBuilder = QueryBuilders.matchQuery("title", "搜");

4、查看es数据

查看索引信息:http://localhost:9200/_cat/indices?v
查看某个索引库结构:http://localhost:9200/blog
查看某个对象:http://localhost:9200/blog/article/1

【SpringBoot】搜索框架ElasticSearch介绍和整合SpringBoot的更多相关文章

  1. 12章 搜索框架ElasticSearch介绍和整合SpringBoot 4节课

    1.搜索引擎知识和搜索框架elasticsearch基本介绍     简介:通过京东电商 介绍什么是搜索引擎,和开源搜索框架ElasticSearch6.x新特性介绍 前言:介绍ES的主要特点和使用场 ...

  2. 【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf

    ========7.SpringBoot常用Starter介绍和整合模板引擎Freemaker.thymeleaf ========================= 1.SpringBoot Sta ...

  3. 通用mapper版+SpringBoot+MyBatis框架+mysql数据库的整合

    转:https://blog.csdn.net/qq_35153200/article/details/79538440 开发环境: 开发工具:Intellij IDEA 2017.2.3 JDK : ...

  4. SpringBoot其他框架-JPA-Hibernate-Swagger

    SpringBoot其他框架 通过了解其他的SpringBoot框架,我们就可以在我们自己的Web服务器上实现更多更高级的功能. 邮件发送:Mail 我们在注册很多的网站时,都会遇到邮件或是手机号验证 ...

  5. 整合springboot(app后台框架搭建四)

    springboot可以说是为了适用SOA服务出现,一方面,极大的简便了配置,加速了开发速度:第二方面,也是一个嵌入式的web服务,通过jar包运行就是一个web服务: 还有提供了很多metric,i ...

  6. 【SpringBoot】息队列介绍和SpringBoot2.x整合RockketMQ、ActiveMQ

    ========================13.消息队列介绍和SpringBoot2.x整合RockketMQ.ActiveMQ ======================= 1.JMS介绍和 ...

  7. SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课

    1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...

  8. 小D课堂 - 零基础入门SpringBoot2.X到实战_第7节 SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf_28..SpringBoot Starter讲解

    笔记 1.SpringBoot Starter讲解     简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-b ...

  9. Dubbo整合Springboot框架

    本文使用的是alibaba的Dubbo. Dubbo整合Springboot可以分为四步: 第一步:首先需要了解Dubbo官方给的建议,至少有三个工程: 接口工程:主要存实体bean和业务接口 服务提 ...

随机推荐

  1. CSS粘住固定底部的5种方法

    本文主要介绍一个Footer元素如何粘住底部,使其无论内容多或者少,Footer元素始终紧靠在浏览器的底部.我们知道,当内容足够多可以撑开底部到达浏览器的底部,如果内容不够多,不足以撑开元素到达浏览器 ...

  2. 【Core】.NET Core中读取App.config配置文件

    1.项目中添加App.config文件 因为.NET Core的项目本质是控制台应用,所以ConfigurationManager的API会去默认读取app.config配置文件,而不是web.con ...

  3. hive新功能cube和rollup

    1.cube简称数据魔方,可以实现hive多个任意维度的查询,cube(a,b,c)则首先会对(a,b,c)进行group by,然后依次是(a,b),(a,c),(a),(b,c),(b),(c), ...

  4. LeetCode--017--电话号码的字母组合(java)

    给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[&quo ...

  5. MYSQL 总结——2

    1.mysql限制显示条目数:Limit,  Offset 图片网址:https://sqlbolt.com/lesson/filtering_sorting_query_results 实例: SE ...

  6. 封装一个使用cURL以POST方式请求https协议的公众方法

    打开php7.2手册,搜索curl function getRequest($url,$type='get', $data = [], $timeout = 10) (需要更改){ $ssl = st ...

  7. createDocumentFragment() 方法

    //createdocumentfragment()方法创建了一虚拟的节点对象,节点对象包含所有属性和方法. //当你想提取文档的一部分,改变,增加,或删除某些内容及插入到文档末尾可以使用create ...

  8. less的基本语法

    参考:http://old.zhufengpeixun.cn/qianduanjishuziliao/mobileDevelopment/2016-07-22/528.html

  9. element-ui <el-input> +<el-tree>使用

    <template> <!-- 需求:通过点击<el-input> 将<el-tree>树型结构打开,选中<el-tree>某个值显示在<e ...

  10. mstOne

    云鸟(2017年6月6日) 1.html标签语义化的好处 a:利于seo优化 b:在样式丢失的时候,还是可以比较好的呈现结构 c:更好的支持各种终端,例如无障碍阅读和有声小说等. d:利于团队开发和维 ...