elastic-search(弹性搜索)讲课资料

上传人:youn****329 文档编号:130125762 上传时间:2020-04-25 格式:PPTX 页数:41 大小:684.74KB
返回 下载 相关 举报
elastic-search(弹性搜索)讲课资料_第1页
第1页 / 共41页
elastic-search(弹性搜索)讲课资料_第2页
第2页 / 共41页
elastic-search(弹性搜索)讲课资料_第3页
第3页 / 共41页
elastic-search(弹性搜索)讲课资料_第4页
第4页 / 共41页
elastic-search(弹性搜索)讲课资料_第5页
第5页 / 共41页
点击查看更多>>
资源描述

《elastic-search(弹性搜索)讲课资料》由会员分享,可在线阅读,更多相关《elastic-search(弹性搜索)讲课资料(41页珍藏版)》请在金锄头文库上搜索。

1、走近elasticsearch 分享人林云霞 概念解释 RESTfulAPI fulltextsearch realtimesearchandanalyticsengine Elasticsearch JSONoverHTTP distributed Lucenebased multitenancy open source hignavailability scalesmassively schemafree 概念解释 ElasticSearch是一个基于Lucene构建的开源 分布式 RESTful搜索引擎 设计用于云计算中 能够达到实时搜索 稳定 可靠 快速 安装使用方便 支持通过HTTP

2、使用JSON进行数据索引 它能够快速搜索数十亿的文件以及PB级的数据 结构化或者非结构化的数据都可以 简介 概念解释 节点一个节点就是集群中的一个服务器 集群点多台Es服务器的结合的统称叫ES集群 一个集群包含多台服务器 多个节点 分片主分片和副本分片 主分片 1N 复制分片 概念解释 索引中的索引是组织数据的逻辑空间 一个索引就是一个拥有几分相似特征的文档的集合 类型在一个索引中 你可以定义一种或多种类型 文档一个文档是一个可被索引的基础信息单元 数据库 表 行 概念解释 索引 index 类型 type 文档 doc 1N 1N 点此添加标题 集群 节点 主分片 副本分片 索引 概念解释

3、文档 概念解释 主节点控制集群 负责集群中的操作 协调创建索引 查询请求客户端节点负载均衡 组装返回的数据给客户端 集群中有很多结点 可以配置为3种不同的角色 系统原理 02 系统原理 Elasticsearch使用了ApacheLucene 其内部使用的是被称为倒排索引的数据结构 存储模型 倒排索引源于实际应用中需要根据属性的值来查找记录 这种索引表中的每一项都包括一个属性值和具有该属性值的各记录的地址 由于不是由记录来确定属性值 而是由属性值来确定记录的位置 因而称为倒排索引 invertedindex 倒排索引 系统原理 文档是Elasticsearch的数据单位 对文档中的词项进行分词

4、 并创建去重词项的有序列表 将词项与其在文档中出现的位置列表关联 便形成了倒排索引 我们来看下如下2个文档是如何被倒排索引的 文档1 Doc1 零售应用开发一室主题分享文档2 Doc2 数据仓库团队主题分享 文档1 Doc1 零售 应用 开发 一室 主题 分享文档2 Doc2 数据 仓库 团队 主题 分享 系统原理 倒排索引 文档1 Doc1 零售 应用 开发 一室 主题 分享文档2 Doc2 数据 仓库 团队 主题 分享 系统原理 当我们查询 数据分享 这一个中文分词时 只需要知道他在哪个文档即可 两个文档都匹配 但是DOC2比其它的有更多的匹配项 相关度评分为2 如果我们加入简单的相似度算

5、法 similarityAndlgorithm 计算匹配单词的数目 这样我们就可以说DOC2这个文档比其它的匹配度更高 这对于我们的查询结果具有更多相关性 系统原理 当我们发送索引一个新文档的请求到协调节点后 将发生如下一组操作 Elasticsearch集群中的每个节点都包含了改节点上分片的元数据信息 协调节点 默认 使用文档ID参与计算 以便为路由提供合适的分片 Elasticsearch使用MurMurHash3函数对文档ID进行哈希 其结果再对分片数量取模 得到的结果即是索引文档的分片 shard hash document id num of primary shards 新建索引

6、系统原理 coordinatingnode shard memorybuilder translog filesystemcache empotytranslog disk writerequest routerequest refreshevery1sec flushevery30minorwhengetstoobig commitwhenevery5secwitheverywriteoperationandwhenflushed committodishwithtranslogflush insideashard 添加标题 posthttp localhost 9200 blog newa

7、rticle 1 author 林云霞 creatDate 20170729 content elasticsearch是一个非常优秀的搜索引擎 place 招银网络科技 新建索引 index blog type newarticle id 1 version 1 result created shards total 3 successful 2 failed 0 created true 系统原理 删除磁盘上的每个段都有一个相应的 del文件 当删除请求发送后 文档并没有真的被删除 而是在 del文件中被标记为删除 该文档依然能匹配查询 但是会在结果中被过滤掉 当段合并 我们将在本系列接下

8、来的文章中讲到 时 在 del文件中被标记为删除的文档将不会被写入新段 更新接下来我们看更新是如何工作的 在新的文档被创建时 Elasticsearch会为该文档指定一个版本号 当执行更新时 旧版本的文档在 del文件中被标记为删除 新版本的文档被索引到一个新段 旧版本的文档依然能匹配查询 但是会在结果中被过滤掉 更新和删除 添加标题 posthttp localhost 9200 blog newarticle 1 author 林云霞 creatDate 20170729 content 简单介绍elasticsearch的基本原理 place 招银网络科技 updateDate 2017

9、0804 更新 index blog type newarticle id 1 version 2 result updated shards total 3 successful 2 failed 0 created false 添加标题 deletehttp localhost 9200 blog newarticle 1 删除 found true index blog type newarticle id 1 version 3 result deleted shards total 3 successful 2 failed 0 系统原理 查询阶段查协调节点向索引中的每个分片 原本或

10、副本 广播 每个分片在本地执行搜索并且建立了匹配document的优先队列 priorityqueue 并将documentIDs返回协调节点取回阶段协调节点将向包含原始文档的分片发起请求 全部分片填充文档信息并将其返回给协调节点 查询 系统原理 searchrequest Priorityqueue Priorityqueue Priorityqueue Priorityqueue queryphasesendrequesttoallshardscreateapriorityqueuetogloballysortresultsreturnedbyshards fetchphasereques

11、tdocumentstoreturnedtotheclientfromindividualshards fetchphasereturndocumentsrequestbythecoordinatingnodeafterenrichingthem queryphaseeachshardsperformssearchlocallycreateapriorityqueueofsizefrom sizeandsortsresultsbyrelevancesenddocumentIDsandscoresofmatchingdocumentstothecoordinatingnode 添加标题 geth

12、ttp localhost 9200 blog newarticle 1 查询 index blog type newarticle id 1 version 2 found true source author 林云霞 creatDate 20170729 content 基本原理了已经介绍完了 place 招银网络科技 updateDate 20170804 分布式集群 03 分布式集群 空集群 分布式集群 http localhost 9200 cluster health cluster name my application status green timed out false

13、number of nodes 1 number of data nodes 1 active primary shards 0 active shards 0 relocating shards 0 initializing shards 0 unassigned shards 0 delayed unassigned shards 0 number of pending tasks 0 number of in flight fetch 0 task max waiting in queue millis 0 active shards percent as number 100 集群健康

14、 分布式集群 http localhost 9200 blog settings number of shards 3 number of replicas 1 添加索引 分布式集群 添加索引 分布式集群 故障转移 分布式集群 随着应用需求的增长 我们该如何扩展 如果我们启动第三个节点 我们的集群会自我感知 这时便成为了三节点集群 横向扩展 分布式集群 http localhost 9200 blog settings number of replicas 2 更多扩展 分布式集群 我们已经说过Elasticsearch可以应对节点失效 所以让我们继续尝试 如果我们杀掉第一个节点的进程 以下简

15、称杀掉节点 看起来像如此 应对故障 应用场景 04 应用场景 场景 使用Elasticsearch作为主要的后端 应用场景 场景二 在现有系统中增加elasticsearch 应用场景 例如 假设要部署一个大规模的日志框架存储 搜索 并分析了大量的事件 场景三 使用elasticsearch和现有的工具 应用场景 1 Wikipedia 维基百科 使用ES提供全文搜索并高亮关键字2 StackOverflow IT问答网站 结合全文搜索与地理位置查询3 Github使用Elasticsearch搜索20TB的数据 包括13亿的文件和1300亿行的代码4 Mozilla5 Sony公司使用elasticsearch作为信息搜索引擎 国外应用示例 应用场景 百度 在云分析 网盟 预测 文库 钱包 风控等业务上都应用了ES 单集群每天导入30TB 数据 总共每天60TB 新浪 阿里巴巴 腾讯等公司均有对ES的使用 国内使用案例 谢谢

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号