基本概念
date
Jul 25, 2021
slug
elasticsearch-guide-basic-concept
status
Published
tags
Elasticsearch
读书
summary
type
Page
Elasticsearch 与 Lucene 的关系
Lucene 是一个高性能的搜索引擎库,但它是一个偏向底层的库,普通用户使用起来比较繁琐复杂,而且要求使用者具有信息检索相关知识,不易于上手。而 Elasticsearch 是在基于 Lucene 开发的,提供了更加简单的 API,并且提供了一套 RESTful API。
几个主要概念
Near Realtime (NRT) 近实时
Elasticsearch 支持近实时搜索,表示从写入一个文档到文档可被搜索期间有一个微小的时间间隔。
Cluster
集群,由多个 Node 组合起来一起提供服务。集群需要有一个唯一的集群名,默认为 elasticsearch。
Node
节点,Cluster 的一部分,存储数据,参与集群的索引和搜索功能。Node 也需要唯一标识名,默认使用 Universally Unique IDentifier (UUID) 分配。Node 可以通过指定 Cluster 名称来加入某一个 Cluster。
Index
是一组 Document 数据的合集,实际上是一组物理 Shard 的逻辑空间。可类比 RDS 中的 Database。
Type
在 6.x 版本之后不建议使用,7.x 版本后被移除。
Mappping
定义了 Index 中存储 Document 的格式和字段类型,可类比 RDS 中的 Schema。
Document
具体一条数据,存储在 Index 中。可类比 RDS 中的一行记录,使用 json 格式存储。
Shard
分片,Elasticsearch 将 Index 分成多个 Shard ,分散存储在集群中,方便扩容,增加可用性。在创建 Index 时可以指定 Shard 的数量。对于将一次搜索请求分散到不同 Shard 上执行,以及将结果聚合起来,都是 Elasticsearch 处理的,对用户透明。引用原文:
- It allows you to horizontally split/scale your content volume
- It allows you to distribute and parallelize operations across shards (potentially on multiple nodes) thus increasing performance/throughput
Replicas
副本,作为 Shard 的备份存在,提升集群高可用程度,默认每个主 Shard 有 5 个分片,可以通过 _settings URI 修改配置。为了做到在主分片挂掉时有副本顶上去,Elasticsearch 要求 shard 和 replica 不能在同一个 Node 上。另外 replica 还可以提供查询,所以 replica 在正常情况下还可以提高集群的吞吐量,提高性能。
- It provides high availability in case a shard/node fails. For this reason, it is important to note that a replica shard is never allocated on the same node as the original/primary shard that it was copied from.
- It allows you to scale out your search volume/throughput since searches can be executed on all replicas in parallel.