知识内容输出不易,请尊重他人劳动成果。严禁随意传播、复制和盗用他人成果或文章内容用以商业或盈利目的!
1、节点:Node
一个节点就是一个Elasticsearch的实例,可以理解为一个 ES 的进程。
注意
- 一个节点 ≠ 一台服务器
如下图为一个在本地启动的服务节点
下面两张图为同一个基于5节点的本地集群
GET _cat/nodes?v
通过 Head 插件查看集群节点信息
2、角色:Roles
角色是ES节点的重要属性,属于Elasticsearch的重要基础概念。
角色在分布式、可扩展的系统架构中发挥着至关重要的作用,但是在ES的应用技术中,不需要过分深入去理解不同角色的具体含义。
如果你已经对 ES 应用层面熟练掌握,请戳:进阶篇:第二章 Elastic分布式原理-角色
2.1 基本概念
在高可用系统架构中,节点角色发挥着至关重要的作用。如果前期没有对业务系统和技术架构做足准备,没有充分考虑后期的扩展问题,势必会为将来的性能优化留下潜在问题。
2.2 常见的角色
- 主节点(active master):一般指活跃的主节点,一个集群中只能有一个,主要作用是对集群的管理。
- 候选节点(master-eligible):当主节点发生故障时,参与选举,也就是主节点的替代节点。
- 数据节点(data node):数据节点保存包含已编入索引的文档的分片。数据节点处理数据相关操作,如 CRUD、搜索和聚合。这些操作是 I/O 密集型、内存密集型和 CPU 密集型的。监控这些资源并在它们过载时添加更多数据节点非常重要。
- 预处理节点(ingest node):预处理节点有点类似于logstash的消息管道,所以也叫ingest pipeline,常用于一些数据写入之前的预处理操作。
2.3 使用和配置方法
准确的说,应该叫节点角色,是区分不同功能节点的一项服务配置,配置方法为
node.roles: [ 角色1, 角色2, xxx ]
注意:
- 如果 node.roles 为缺省配置,那么当前节点具备所有角色
2.4 节点角色进阶讲解
3、索引:Index
3.1 索引是什么
索引在 ES 中所表述的含义和 MySQL 中的索引完全不同,在 MySQL 中索引指的是加速数据查询的一种特殊的数据结构,如 normal index。
而在 ES 中,索引表述的含义等价于 MySQL 中的表(仅针对 ES 7.x 以后版本),注意这里只是类比去****,**************。
3.2 **************
- alias:** ********,**************,************,**:ES**********(alias)**************
- settings:********,****************************。
- mapping:******,************************,**************、****、********。
3.3 ********
** ES **,********************************************:
- **************:**************,**************,******** index 。****:****** ******** product ****,********** ES ************** product ********“**”。
- ************:******************************************,****************************,******、FST **。****:********** ******** ** ********(**********************)。****************,****************************,******************************************,************************,
- ******************:************************,** ES **********************************,**** index **** doc ****。****************************************。
4、****:Type(ES 7.x ********************)
4.1 **************
** Elasticsearch ****************,********************************************。****************************************,**** product ************ user ****** order ****。
******************************,****** user ************** user_name ****、**** title ********** email ****,**** order ************** content ****、**** title ****,****** user ********,********user_name****。
****************_type ************************,****** URL **************,******************************:
GET product/user,order/_search
{
"query": {
"match": {
"user_name": "******"
}
}
}
4.2 ************ type ******
****,“****”****** SQL **********“******”,“****”******“**”。**
****** | ES 6.x ********** | ES 7.x ********** |
---|---|---|
_index | DataBase | Table |
_type | Table | ******:“_doc” |
_doc | Row | Row |
- **********:******************,****************************。** SQL ********,**************。************************************。********************,************。
- ************:** Elasticsearch ******,********************************************** Lucene ********。********,**************,******** user_name ****** user ** order **************************** user_name ****** ,******** user_name **********************************(****)。
- ********:**********,******************************************************************** Lucene ******************。
************,********** Elasticsearch ********************。
4.3 ********
******************
**************************************,******** user ** order ****************。********************,********************************。
******************:
- **************,**********,****** Lucene ******************。
- ********************************************,**************************************。
- ************,**************************。********************************************
4.4 ****************
ES 5.6.0
- ************index.mapping.single_type: true********** 6.0 ****************************。
- parent-child**join************** 5.6 ************。
ES 6.x
- ** 5.x **************** 6.x **************,****** 5.x ******。
- ** 6.x **************************************。**********************,************。**************_doc,******** API ****** 7.0 ************:
PUT {index}/_doc/{id}**POST {index}/_doc
- _type ************ **** ****_id****_uid 。**_uid************_id**********。
- **********************/**,********** join****。
- **********_default_********。
- ** 6.8 **,********、************** API ****************** ( include_type_name),**************************************。********true,************************************** 7.0。******include_type_name **************。************************************_doc。
ES 7.x
- **********************。****,********************type。******** API ****PUT {index}/_doc/{id}****** ID **POST {index}/_doc ********** ID。******,** 7.0 **,_doc****************,**************************。
- ********、************** API ****include_type_name************false. **************************。
- _default_************** 。
ES 8.x
- ************************。
- **include_type_name**********。
5、****:Document
5.1 **************:doc struct
**************************,**********。
- _index:********
- _id:**** id。
- _version:******
- _seq_no:****************,********************** _seq_no
- _primary_term:_primary_term**********,****Primary Shard**************,************,Primary****************,_primary_term******1。****************************************_seq_no ************,**** Primary Shard ******************。
5.3 ******:source data
**********,********************。
6、****:Cluster
6.1 ********
****************************
****
- ********(**********、********、********)****,******************,****************。
- **************************,****************,****************,******,********。
6.2 **********
********************
![]() |
![]() |
---|---|
6.3 ********
ES ************,********,********,****************,Elasticsearch ************************************9300**9305******************************,************。******************************************。
6.4 ********
- network.host:************ip****,************************************,**************************************,****************。
- network.publish_host:************ip****,************************************
- http.port:**********,**** 9200,********** 9200~9299
- transport.port:************,**** 9300,********** 9300~9399
- discovery.seed_hosts:**********************************,******************************************。************** IP ****,************ DNS **************** IP ************。
- cluster.initial_master_nodes:********************************,************,************************,********** network.host,******************。****************************************************。
****************
6.5 ****************
6.5.1 ********
- ****:**************
- ****:********************,********************,****************************,**************。
- ****:**********************,**********。******************************。**********。
6.5.2 **********
******:_cat API
GET _cat/health
************
GET _cluster/health
************
**************************:**********************,****************************,************************。********** API ********************。
6.6.1 Cat APIs:
****APIs:
- _cat/indices?health=yellow&v=true:************************
- _cat/health?v=true:************
- _cat/nodeattrs:************
- _cat/nodes?v:****************
- _cat/shards:****************************
6.6.2 Cluster APIs
- _cluster/allocation/explain:************************
- _cluster/health/
:************
6.6.3 ****************
- ALLOCATION_FAILED: ************************
- CLUSTER_RECOVERED: ************************.
- DANGLING_INDEX_IMPORTED: ************************.
- EXISTING_INDEX_RESTORED: **************************.
- INDEX_CREATED: ****API****************.
- INDEX_REOPENED: ************************.
- NEW_INDEX_RESTORED: ************************.
- NODE_LEFT: **********************************.
- REALLOCATED_REPLICA: ************************************.
- REINITIALIZED: ********“****”****“******”**.
- REPLICA_ADDED: ******************************.
- REROUTE_CANCELLED: **********************************.
7、****:Shard
7.1 **************
******************,************** **********。******************************
7.2 **********
- ******(primary shard):
- ********(replica shard):
7.3 **************
- **************************,**7.0******************,******************;**7.0******************。******************************,********************************,************
- ****************Lucene****,********************************
- ES********nodes************ shard reblance
- ****doc****************************,**********************************,************************。
******************
**************************。**************
**************************。
7.4 ****************
- ********:************************。
- ********:************************************
- ******:****************************,**********************,**************。