注意:本文档不会维护,可查看持续维护文档 https://blog.youkuaiyun.com/weixin_43834662/article/details/102781208
keyword
analysis
:分词,依赖于analyzer
分词器analyzer
:分词器cluster
: 集群cross-cluster replication (CCR)
:跨集群复制,同网络数据迁移非常快速,但是在遇到灾难时,数据安全性没法保障。为了应对这个问题,采用CCR。CCR is active-passive. 主集群负责读、写。复本集群只负责读cross-cluster search (CCS)
:跨集群搜索document
:文档field
:字段filter
:过滤,结果只有yes
orno
,没有score
follower index
:CCR跨集群复制的目标索引。存在于本地集群,复制leader indices
leader indices
:CCR跨集群复制的源索引。存在于远端,被复制到follower indices
mapping
:映射,定义type
和相关设置node
:集群中运行的实例,多个node
可以在一台机器上运行,但通常情况是一台server一个nodeid
:文档id,可自定义或ES自动生成index
:索引(名词),类似数据库名(database)shard
:一个shard是一个单独的Lucene实例。是一个级别的工作单元,由ES自动管理。ES负责把所有的shard分布到集群所有节点中,同时负责在节点发生变更时移动分片。在单个ES shard(Lucene Index)中有最大document数限制,每个分片能存储的文档数是由 Lucene决定的,约21亿(=Integer.MAX_VALUE - 128)
primary shard
:主分片,每个文档都被存于一个主分片中。当索引文档是,先在主分片索引,然后在所有复分片索引。所有修改都在主分片,该主分片负责同步数据到副分片replica shard
:复分片,每个主分片有0个或者多个复分片,一个复分片是主分片的复本,主要作用有:容错;提高get和search性能query
:两种类型的query:scoring queries
和filters
recovery
:从一个源分片同步一个分片复本的过程routing
:路由,一个文档存于一个主分片。哪个主分片?由routing
而来。默认是通过ID routing
souce field
:默认情况下,我们索引的JSON文档,被保存于_source
字段中term
:词,被索引到ES中的一个准确的值。foo,Foo,FOO是不同的termtext
:常见的非结构化的文本type
:类似于数据库表名(table),6.X deprecated,7.X已经不支持了,只能是_doc
inverted index
:倒排索引,搜索中最核心的概念,是其可以进行快速搜索的原因ILM
:index lifecycle management,索引生命周期管理。详情
相关重点
text
被存于倒排索引中,number
和geo
被存于 BKD tree中- 主分片不可变,副本分片可变
- 一般来讲,每个分片的大小在20GB-40GB
NRT
: near real time, 近实时,大概有1s延时(refresh interval默认设置为1s)ES更新过程,先删除已有的索引,然后再重新新建索引
- ES7 自带 JDK,如果需要使用自己的 JDK,需设置 JAVA_HOME, 但是自定义 JDK 必须在 ES 的支持列表中,否则无法启动 ES
ES_JAVA_OPTS
-Xms
-Xmx
设置成一样的值,比如:-e ES_JAVA_OPTS="-Xms16g -Xmx16g"
- Docker安装ES详细说明
- JVM
- Xms (minimum heap size)
- Xmx (maximum heap size)
- Set Xmx and Xms to no more than 50% of your physical RAM
- set these two settings to be equal to each other
- 写操作
- 操作步骤
- routing(ID) -> 主分片
- 数据校验(格式是否正确,id是否合法…),本地 indexing or deleting
- 通知 副分片 同步数据(
in-sync copies set
并行同步) - 所有副分片同步成功后,主分片告诉客户端操作完成
- 出现问题场景
- 主分片出现问题,
Master
会收到通知,Master
会选择一个副分片作为主分片 - 如果副分片出现问题,会通知
Master
把该分片从in-sync copies set
中删除,然后再通知client
Master
会启动新的分片,保证集群健康
- 主分片出现问题,
- 操作步骤
- 读操作
- 协调节点
coordinating node
收到读请求, 解析请求,并把请求发送到相关的分片 - 从 分片副本群
the shard replication group
里面选择一个相关的分片获取有效数据(主、从分片), 采用 round robin算法 - 发送分片级别请求到选定复本
- 协调节点合并请求结果(通过ID获取数据没有这一步)
- 协调节点
- 读操作失败:会发送请求到另一个分片
the shard replication group
。为了快速响应,Search
、Multi Search
、Bulk
、Multi Get
再分片失败,立马返回(快速失败,不会把请求发送到另一个分片)
加载测试数据
- accounts.json, 格式如下:
{"index":{"_id":"1"}}
{"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
{"index":{"_id":"6"}}
{"account_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36,"gender":"M","address":"671 Bristol Street","employer":"Netagy","email":"hattiebond@netagy.com","city":"Dante","state":"TN"}
{"index":{"_id":"13"}}
{"account_number":13,"balance":32838,"firstname":"Nanette","lastname":"Bates","age":28,"gender":"F","address":"789 Madison Street","employer":"Quility","email":"nanettebates@quility.com","city":"Nogal","state":"VA"}
- 导入数据
curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"
curl "localhost:9200/_cat/indices?v"
Cluster Health
GET _cat/health
GET _cluster/health
GET _cat/nodes
GET _cat/shards
GET _cat/indices
create, index, query, delete
PUT /customer?pretty
PUT /customer/_doc/1?pretty
{
"name": "John Doe"
}
POST /customer/_doc?pretty
{
"name": "Jane Doe"
}
POST /customer/_update/1?pretty
{
"doc": { "name": "Jane Doe", "age": 20 }
}
POST /customer/_update/1?pretty
{
"script" : "ctx._source.age += 5"
}
GET /customer/_doc/1?pretty
GET /customer/_search
{
"query": {
"match_all": {}
}
}
DELETE /customer/_doc/1?pretty
DELETE /customer?pretty
Batch Processing
当个操作失败,还是会执行其他操作,整个请求结果正常返回,每个操作都会有对应的操作结果(按请求排序)。
POST /customer/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}